/* ============================================================
   نظام المكتب الهندسي — الألوان والخطوط من الصفحات التجريبية
   ============================================================ */
:root {
  --bg: #F4F2EE;
  --surface: #FFFFFF;
  --ink: #1B2230;
  --muted: #5B6270;
  --line: #E3DFD8;
  --line-soft: #F0EDE7;
  --track: #ECE9E3;
  --accent: #1F4E79;
  --accent-hover: #163A5B;
  --accent-soft: #E6EEF6;
  --warn: #8A3F00;
  --warn-soft: #FBEBDD;
  --ok: #1E6B45;
  --ok-soft: #E3F1E8;
  --danger: #A61B1B;
  --nav: #1B2230;
  --nav-active: #2C3646;
  --nav-text: #C9D1DC;
  --pin: #C2410C;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0; font-size: 17px; }
h3 { margin: 0; font-size: 15px; }
input, select, textarea, button { font: inherit; color: inherit; }

/* ---------- الهيكل ---------- */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.nav {
  flex: 1 1 220px; max-width: 100%; background: var(--nav); color: #fff;
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.nav .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; font-size: 17px; }
.nav a { color: var(--nav-text); padding: 10px 12px; border-radius: 8px; }
.nav a.active { color: #fff; background: var(--nav-active); font-weight: 600; }
.nav a:hover { color: #fff; }
.nav .who { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--nav-active); font-size: 13px; color: var(--nav-text); }
.nav .who button { background: none; border: 0; color: #9CC3E6; padding: 0; cursor: pointer; margin-top: 4px; }
.main { flex: 999 1 560px; min-width: 0; padding: 24px 28px; display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 700px) {
  .nav { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .nav .brand { width: 100%; padding-bottom: 6px; }
  .nav .who { width: 100%; margin-top: 6px; }
  .main { padding: 16px; }
}

/* ---------- عناصر ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi .v { font-size: 30px; font-weight: 700; margin-top: 4px; }
.kpi .v small { font-size: 14px; font-weight: 500; }
.split { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.split > .wide { flex: 2 1 480px; min-width: 0; }
.split > .narrow { flex: 1 1 300px; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: #C9C3B8; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #E7C4C4; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; background: var(--track); color: #3E4654; white-space: nowrap; }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: #F8E1E1; color: var(--danger); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; font-weight: 500; color: var(--muted); padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.voided td { color: var(--muted); text-decoration: line-through; }
.num { font-variant-numeric: tabular-nums; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #3E4654; }
.field input, .field select, .field textarea, input.inp, select.inp {
  min-height: 42px; border: 1px solid #D6D1C8; border-radius: 8px; padding: 8px 10px; background: #fff; font-size: 14px;
}
.field textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 18px; height: 18px; }

.search { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; min-height: 42px; min-width: 240px; }
.search input { border: 0; outline: 0; flex: 1; background: transparent; font-size: 14px; }

.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs button { min-height: 44px; padding: 0 16px; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.error-box { background: #F8E1E1; color: var(--danger); border-radius: 10px; padding: 10px 14px; font-size: 14px; }

/* ---------- لوحة المراحل ---------- */
.board { overflow-x: auto; padding-bottom: 8px; }
.board-cols { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; min-width: 1350px; }
.board-col { background: var(--track); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.board-col h2 { font-size: 14px; display: flex; justify-content: space-between; padding: 2px 4px; }
.ocard { display: block; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px; color: var(--ink); }
.ocard:hover { border-color: var(--accent); color: var(--ink); }
.ocard .t { font-weight: 600; font-size: 14px; }
.bar { height: 6px; background: var(--track); border-radius: 99px; margin-top: 8px; }
.bar > i { display: block; height: 6px; background: var(--accent); border-radius: 99px; }

.stepper { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; font-size: 12px; }
.stepper li { padding: 8px 4px; border-top: 4px solid #D6D1C8; color: var(--muted); }
.stepper li.done { border-color: var(--ok); color: var(--ok); }
.stepper li.now { border-color: var(--accent); color: var(--accent); font-weight: 700; }
@media (max-width: 700px) { .stepper { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- المخططات ---------- */
.vlist { display: flex; flex-direction: column; gap: 8px; }
.vitem { text-align: right; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; cursor: pointer; width: 100%; }
.vitem.on { border: 2px solid var(--accent); background: var(--accent-soft); }
.phase-h { font-size: 12px; color: var(--muted); margin-top: 6px; }
.viewer { position: relative; background: #1E2430; min-height: 260px; display: flex; align-items: center; justify-content: center; color: #C9D1DC; }
.viewer img { display: block; width: 100%; height: auto; cursor: crosshair; }
.pin {
  position: absolute; transform: translate(50%, -50%); width: 28px; height: 28px; border-radius: 99px;
  background: var(--pin); color: #fff; border: 2px solid #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; pointer-events: none;
}
.pin.new { background: var(--accent); }
.pin.resolved { background: #7A8290; }
.cnum { flex: none; width: 24px; height: 24px; border-radius: 99px; background: var(--pin); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.cnum.none { background: var(--track); color: var(--muted); }

/* ---------- نوافذ ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 24, 32, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: var(--radius); padding: 22px; width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; }
.modal.wide { width: min(820px, 100%); }
.editor-back { position: fixed; inset: 0; background: #1E2430; z-index: 60; display: flex; flex-direction: column; }
.editor-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 14px; background: var(--nav); color: #fff; }
.editor-bar .btn { color: var(--ink); }
.editor-back iframe { flex: 1; border: 0; width: 100%; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 80; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: min(380px, 100%); }

/* ---------- الإيصال للطباعة ---------- */
.receipt { max-width: 640px; margin: 0 auto; }
.receipt .rhead { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--ink); padding-bottom: 12px; }
.receipt dl { display: grid; grid-template-columns: 140px 1fr; gap: 10px; margin: 16px 0; }
.receipt dt { color: var(--muted); }
.receipt dd { margin: 0; font-weight: 500; }
.receipt .amount { font-size: 26px; font-weight: 700; }
.receipt .sign { display: flex; justify-content: space-between; margin-top: 48px; }
@media print {
  .nav, .no-print, #toast { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
  .card { border: 0; }
}
