:root {
  --petrol: #0E4D4A;
  --petrol-2: #136460;
  --petrol-soft: #DCEAE8;
  --paper: #EEF2F1;
  --surface: #FFFFFF;
  --ink: #17201F;
  --ink-2: #4A5856;
  --ink-3: #7A8886;
  --line: #D6DEDC;
  --line-2: #E6ECEB;
  --stamp: #B4372D;
  --stamp-soft: #F7E3E0;
  --ochre: #A86A12;
  --ochre-soft: #F6EBD6;
  --green: #2F7D4F;
  --green-soft: #DFF0E5;
  --radius: 6px;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
a { color: var(--petrol); }
a:hover { color: var(--petrol-2); }
:focus-visible { outline: 2px solid var(--petrol); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
small, .muted { color: var(--ink-3); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--petrol); color: #fff; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px; border: 2px solid rgba(255,255,255,.85); border-radius: 50%;
  display: grid; place-items: center; font-size: 17px; transform: rotate(-8deg);
}
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a {
  display: flex; justify-content: space-between; align-items: center;
  color: rgba(255,255,255,.82); text-decoration: none; padding: 9px 12px; border-radius: var(--radius);
}
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a.on { background: #fff; color: var(--petrol); font-weight: 600; }
.count { background: var(--stamp); color: #fff; font-size: 12px; font-weight: 600; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; padding: 0 6px; }
.side nav a.on .count { background: var(--petrol); }
.count.calm { background: rgba(255,255,255,.18); }
.side nav a.on .count.calm { background: var(--petrol-soft); color: var(--petrol); }
.new-btn { color: #fff; border: 1px dashed rgba(255,255,255,.5); border-radius: var(--radius); padding: 9px 12px; text-decoration: none; text-align: center; }
.new-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.me { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid rgba(255,255,255,.15); padding: 14px 6px 0; }
.me strong { display: block; font-weight: 600; }
.me small { color: rgba(255,255,255,.6); }
.me a { color: rgba(255,255,255,.75); font-size: 14px; }

.main { padding: 28px 32px 60px; min-width: 0; max-width: 1280px; }
.main.solo { margin: 0 auto; max-width: 420px; padding-top: 12vh; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

/* ---------- Surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.panel > .body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Flash ---------- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.f-ok { background: var(--green-soft); border-color: #B9DCC5; color: #1D5535; }
.f-err { background: var(--stamp-soft); border-color: #E9BDB7; color: #7E231B; }
.f-warn { background: var(--ochre-soft); border-color: #E6CF9F; color: #6E4407; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 13px; font-weight: 500; padding: 2px 10px; border-radius: 4px; white-space: nowrap; }
.t-idle { background: #E5E9F2; color: #33415C; }
.t-work { background: var(--petrol-soft); color: var(--petrol); }
.t-wait { background: var(--ochre-soft); color: #7A4C0B; }
.t-done { background: var(--green-soft); color: #1D5535; }
.t-lost { background: #ECEEEE; color: var(--ink-3); text-decoration: line-through; }
.late { color: var(--stamp); font-weight: 600; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--petrol);
  background: var(--petrol); color: #fff; white-space: nowrap;
}
.btn:hover { background: var(--petrol-2); color: #fff; }
.btn.ghost { background: transparent; color: var(--petrol); }
.btn.ghost:hover { background: var(--petrol-soft); color: var(--petrol); }
.btn.danger { background: transparent; color: var(--stamp); border-color: #E3B3AD; }
.btn.danger:hover { background: var(--stamp-soft); }
.btn.big { padding: 11px 22px; font-size: 15px; }
.btn.sm { padding: 4px 10px; font-size: 13px; font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--petrol); cursor: pointer; text-decoration: underline; }
.link-btn.danger { color: var(--stamp); }

label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--petrol); box-shadow: 0 0 0 3px var(--petrol-soft); }
textarea { min-height: 80px; resize: vertical; }
input[type=file] { font: inherit; font-size: 14px; max-width: 100%; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: right; font-size: 13px; font-weight: 500; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #F7F9F9; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: #F5F8F8; }
td.num, th.num { text-align: left; direction: ltr; }
.ref { font-weight: 600; color: var(--ink-2); font-size: 13px; direction: ltr; unicode-bidi: isolate; }
.subj { font-weight: 500; color: var(--ink); text-decoration: none; display: block; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px 18px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { max-width: 280px; }
.filters select { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { text-decoration: none; padding: 5px 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff; color: var(--ink-2); font-size: 14px; }
.chip b { font-weight: 600; color: var(--ink); margin-inline-start: 4px; }
.chip.on { background: var(--petrol); border-color: var(--petrol); color: #fff; }
.chip.on b { color: #fff; }

/* ---------- Dashboard ---------- */
.pipeline { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; overflow: hidden; }
.pipeline a { text-decoration: none; color: inherit; padding: 14px 14px 12px; border-inline-start: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 2px; }
.pipeline a:first-child { border-inline-start: 0; }
.pipeline a:hover { background: #F5F8F8; }
.pipeline .n { font-size: 26px; font-weight: 700; line-height: 1.2; }
.pipeline .lbl { font-size: 13px; color: var(--ink-2); }
.pipeline .val { font-size: 12px; color: var(--ink-3); direction: ltr; text-align: right; }
.pipeline a.hot .n { color: var(--stamp); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.kpi .l { font-size: 13px; color: var(--ink-2); }
.kpi.alert .v { color: var(--stamp); }

.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { padding: 10px 18px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.alerts li:last-child { border-bottom: 0; }
.alerts a { text-decoration: none; font-weight: 500; }
.alerts .why { font-size: 13px; color: var(--stamp); white-space: nowrap; }

/* ---------- Journey track (the signature element) ---------- */
.journey { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin: 0 0 20px; position: relative; padding: 4px 0 0; }
.journey::before { content: ""; position: absolute; top: 31px; right: 8%; left: 8%; border-top: 2px dashed var(--line); }
.stop { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.seal {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--line); background: var(--paper); color: var(--ink-3);
  font-size: 13px; font-weight: 600; position: relative; z-index: 1;
}
.stop.done .seal { border: 2px solid var(--petrol); color: var(--petrol); background: #fff; transform: rotate(-9deg); box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 4px var(--petrol); }
.stop.now .seal { border: 2px solid var(--petrol); background: var(--petrol); color: #fff; }
.stop.lost .seal { border-color: var(--stamp); color: var(--stamp); background: #fff; transform: rotate(-9deg); }
.stop .nm { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.stop.done .nm, .stop.now .nm { color: var(--ink); }
.stop .dt { font-size: 12px; color: var(--ink-3); direction: ltr; min-height: 18px; }
@media (prefers-reduced-motion: no-preference) {
  .stop.just .seal { animation: press .45s cubic-bezier(.2,1.4,.4,1) both; }
  @keyframes press { 0% { transform: scale(1.5) rotate(-20deg); opacity: 0; } 100% { transform: rotate(-9deg); opacity: 1; } }
}

/* ---------- Request page ---------- */
.req-head { margin-bottom: 18px; }
.req-head .meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--ink-2); font-size: 14px; margin-top: 6px; }
.req-head h1 { font-size: 22px; }
.owner-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; background: var(--ochre-soft); border: 1px solid #E6CF9F; border-radius: var(--radius); margin-bottom: 20px; }
.owner-bar.mine { background: var(--petrol-soft); border-color: #B7D2CF; }
.owner-bar.other { background: #fff; border-color: var(--line); }

dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
dl.facts dt { color: var(--ink-3); }
dl.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.items { min-width: 960px; }
.items input, .items select { padding: 6px 8px; font-size: 14px; }
.items td { padding: 6px 8px; }
.items .c-no { width: 36px; color: var(--ink-3); text-align: center; }
.items .c-qty { width: 84px; }
.items .c-unit { width: 104px; }
.items .c-price { width: 120px; }
.items .c-total { width: 130px; font-weight: 600; text-align: left; direction: ltr; white-space: nowrap; }
.items .c-x { width: 34px; }
.items td.c-desc { min-width: 240px; }
.items tfoot td { border: 0; padding: 4px 8px; }
.items tfoot .lbl { text-align: left; color: var(--ink-2); }
.items tfoot .grand td { font-size: 16px; font-weight: 700; padding-top: 8px; }
.margin-pill { font-size: 13px; padding: 2px 8px; border-radius: 4px; background: var(--green-soft); color: #1D5535; }
.margin-pill.low { background: var(--stamp-soft); color: #7E231B; }
.x-btn { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px; }
.x-btn:hover { color: var(--stamp); }

.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.files li:last-child { border-bottom: 0; }
.files a { text-decoration: none; overflow-wrap: anywhere; }
.files .kind { font-size: 12px; color: var(--ink-3); white-space: nowrap; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.timeline li { padding: 8px 0 8px; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border-bottom: 0; }
.timeline .who { font-weight: 600; }
.timeline .when { color: var(--ink-3); font-size: 12px; }
.timeline .det { color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }

.mail { border-top: 1px solid var(--line-2); padding: 14px 0; }
.mail:first-child { border-top: 0; padding-top: 0; }
.mail .from { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; flex-wrap: wrap; }
.mail .text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; color: var(--ink-2); margin-top: 8px; max-height: 320px; overflow: auto; background: #F7F9F9; padding: 10px 12px; border-radius: var(--radius); }

.stage-form { border-top: 1px solid var(--line-2); padding-top: 14px; margin-top: 14px; }
.stage-form .field-set { display: none; }
.stage-form .field-set.on { display: block; }

details.tuck summary { cursor: pointer; color: var(--petrol); font-weight: 500; font-size: 14px; }
details.tuck[open] summary { margin-bottom: 12px; }

.login h1 { margin-bottom: 4px; }
.login .panel { padding: 24px; margin-top: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .pipeline { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pipeline a:nth-child(5) { border-inline-start: 0; }
  .pipeline a:nth-child(n+5) { border-top: 1px solid var(--line-2); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side, .main { min-width: 0; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px; }
  .side nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; gap: 4px; }
  .side nav a { white-space: nowrap; gap: 6px; }
  .new-btn { order: 2; margin-inline-start: auto; padding: 6px 10px; font-size: 14px; }
  .me { display: none; }
  .main { padding: 18px 16px 48px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline a { border-inline-start: 0 !important; border-top: 1px solid var(--line-2); }
  .journey .seal { width: 42px; height: 42px; font-size: 11px; }
  .journey::before { top: 24px; }
  .stop .nm { font-size: 12px; }
  .stop .dt { font-size: 10px; }
  .subj { max-width: 220px; }
}

/* ---------- Print (quotation) ---------- */

/* ---------- Clients ---------- */
.client-picker .cp-new { border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px 12px 2px; margin-bottom: 12px; background: #F9FBFB; }
.client-picker [data-cp-info] { margin: -6px 0 12px; direction: ltr; text-align: right; }
.client-picker [hidden] { display: none !important; }

/* ---------- Finance (phase 1) ---------- */
.kpis.mini { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0; }
.kpis.mini > div { border: 1px solid var(--line-2); border-radius: var(--radius); padding: 10px 12px; background: #F9FBFB; }
.kpis.mini span { display: block; font-size: 12px; color: var(--ink-3); }
.kpis.mini strong { font-size: 17px; }
.kpis.mini .good strong { color: var(--green); }
.kpis.mini .bad strong { color: var(--stamp); }
.approval-box { background: var(--ochre-soft); border-bottom: 1px solid var(--line-2); }
.approval-box.returned { background: var(--stamp-soft); }
.revisions { border-bottom: 1px solid var(--line-2); display: grid; gap: 8px; }
.rev { border-inline-start: 3px solid var(--ochre); padding: 4px 10px; background: #FFFBF3; font-size: 14px; }
tr.draft td { background: #FFFBF3; }
details.inline-pop { position: relative; }
details.inline-pop > summary { list-style: none; cursor: pointer; display: inline-block; }
details.inline-pop > summary::-webkit-details-marker { display: none; }
details.inline-pop[open] > form { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; min-width: 280px; }
.c-sup { width: 150px; }
.num-pos { color: var(--green); } .num-neg { color: var(--stamp); }
h2 .badge { font-size: 12px; vertical-align: middle; margin-inline-start: 6px; }
.filters.wide { align-items: end; }
.filters .field { margin: 0; min-width: 140px; }
@media (max-width: 820px) { .kpis.mini { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}
