:root {
  --slate: #3e5a73;
  --slate-dark: #2f4659;
  --steel: #4e7295;
  --steel-dark: #3c5c7c;
  --line: #a9bfd3;
  --line-soft: #cfdbe6;
  --band: #dce8f1;
  --row-alt: #eef4f9;
  --ink: #1f2d38;
  --muted: #5b6d7c;
  --ok: #1f7a4d;
  --warn: #9a6b00;
  --bad: #a33;
  --shadow: 0 2px 10px rgba(31, 45, 56, .12);
  --radius: 8px;
  --maxw: 1180px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: #f4f7fa;
  font-family: "Cairo", "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.75;
}

/* ---------- Top navigation ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--slate);
  border-bottom: 3px solid var(--steel-dark);
}
.topbar .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  min-height: 46px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}
.topbar a {
  color: #eaf2f9;
  text-decoration: none;
  font-size: 12.8px;
  padding: 9px 9px;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
  flex: 0 0 auto;
}
.topbar a:hover { background: var(--steel-dark); }
.topbar a.active { background: #fff; color: var(--slate-dark); font-weight: 700; }
.topbar .spacer { flex: 1; }

/* ---------- Header band ---------- */
.masthead {
  background: #fff;
  border-bottom: 1px solid var(--line-soft);
}
.masthead .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.masthead .brand { display: flex; align-items: center; gap: 14px; }
.masthead .brand img { height: 104px; width: auto; display: block; }
.masthead .client img { height: 66px; width: auto; display: block; }
.logo-slot { position: relative; }
.logo-slot input[type=file] { display: none; }
.logo-controls { display: flex; gap: 6px; margin-top: 4px; justify-content: center; }

.infostrip {
  background: var(--band);
  border-bottom: 1px solid var(--line);
}
.infostrip .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  justify-content: center;
  font-size: 13px;
  color: var(--slate-dark);
}
.infostrip span { white-space: nowrap; }

/* ---------- Page shell ---------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px 60px;
}
.page-title {
  text-align: center;
  margin: 26px 0 6px;
  font-size: 25px;
  font-weight: 800;
  color: var(--slate-dark);
}
.page-sub {
  text-align: center;
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 14.5px;
}

/* ---------- Section headings ---------- */
h2.section {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 38px 0 14px;
  font-size: 21px;
  color: var(--slate-dark);
  font-weight: 800;
  scroll-margin-top: 70px;
}
h2.section::before,
h2.section::after {
  content: "";
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--line));
}
h2.section::after { background: linear-gradient(90deg, var(--line), transparent); }
h3 { color: var(--steel-dark); font-size: 17px; margin: 22px 0 8px; }

.card {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin: 16px 0;
}

/* ---------- KPI ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.kpi {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-top: 4px solid var(--steel);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.kpi .v { font-size: 24px; font-weight: 800; color: var(--steel-dark); }
.kpi .l { font-size: 13px; color: var(--muted); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
table.data {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 14px;
  min-width: 560px;
}
table.data caption {
  caption-side: top;
  text-align: center;
  font-weight: 800;
  color: var(--slate-dark);
  padding: 8px;
  font-size: 16px;
}
table.data th {
  background: var(--steel);
  color: #fff;
  font-weight: 700;
  padding: 9px 10px;
  border: 1px solid var(--steel-dark);
  text-align: center;
  white-space: nowrap;
}
table.data td {
  border: 1px solid var(--line-soft);
  padding: 8px 10px;
  text-align: center;
  vertical-align: middle;
}
table.data tbody tr:nth-child(even) { background: var(--row-alt); }
table.data tbody tr:hover { background: #e2eef8; }
table.data td.txt { text-align: right; }
table.data tfoot td {
  background: var(--band);
  font-weight: 800;
  color: var(--slate-dark);
}
.pill {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid currentColor;
}
.pill.yes { color: var(--ok); }
.pill.opt { color: var(--warn); }
.pill.no { color: var(--bad); }

/* ---------- Buttons / controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--steel);
  background: #fff;
  color: var(--steel-dark);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--band); }
.btn.primary { background: var(--steel); color: #fff; }
.btn.primary:hover { background: var(--steel-dark); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }

.controls {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin: 18px 0;
}
.controls .group { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.controls label { font-size: 13.5px; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.controls .sep { width: 1px; height: 26px; background: var(--line-soft); }
.export-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  max-height: 168px;
  overflow-y: auto;
  width: 100%;
  padding: 4px 0;
}
.print-this {
  margin-inline-start: 10px;
  font-weight: 600;
  flex: 0 0 auto;
}
h2.section .print-this,
h3 .print-this { font-size: 12px; padding: 2px 8px; }

/* ---------- Callouts ---------- */
.note {
  border-right: 5px solid var(--steel);
  background: var(--band);
  padding: 12px 16px;
  border-radius: 6px;
  margin: 14px 0;
}
.note.warn { border-right-color: var(--warn); background: #fdf5e2; }
.note.ok { border-right-color: var(--ok); background: #e9f6ee; }
.note.bad { border-right-color: var(--bad); background: #fbeaea; }
.note h4 { margin: 0 0 6px; font-size: 15px; }
ul.tick, ol.steps { padding-right: 22px; margin: 8px 0; }
ul.tick li, ol.steps li { margin: 4px 0; }

/* ---------- Diagrams ---------- */
.diagram-box {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  margin: 14px 0;
}
.diagram-box svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }

/* ---------- Gantt ---------- */
.gantt { overflow-x: auto; }
.gantt table { border-collapse: collapse; min-width: 900px; font-size: 12.5px; }
.gantt th, .gantt td { border: 1px solid var(--line-soft); text-align: center; padding: 4px 6px; }
.gantt th { background: var(--steel); color: #fff; }
.gantt .branch { text-align: right; white-space: nowrap; background: #fff; font-weight: 700; }
.bar { height: 16px; border-radius: 4px; background: var(--steel); }
.bar.phase1 { background: #3e5a73; }
.bar.phase2 { background: #4e7295; }
.bar.phase3 { background: #6a95ba; }
.bar.phase4 { background: #8fb8d8; }
.bar.phase5 { background: #b3d0e6; }

/* ---------- Datasheet links ---------- */
a.ds { color: var(--steel-dark); font-weight: 700; text-decoration: none; border-bottom: 1px dotted var(--steel); }
a.ds:hover { color: var(--steel); }
.ds-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.ds-card { background: #fff; border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.ds-card h4 { margin: 0 0 6px; color: var(--slate-dark); }
.ds-card p { margin: 0; font-size: 13px; color: var(--muted); }

/* Datasheet navigation */
.ds-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  margin: 26px 0 10px;
}
.ds-nav .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  color: var(--steel-dark);
  text-decoration: none;
  background: #fff;
}
.chip:hover { background: var(--band); }
.chip.current { background: var(--steel); color: #fff; border-color: var(--steel-dark); }

/* ---------- RFQ editable pricing ---------- */
table.data.rfq td { padding: 4px 6px; }
table.data.rfq input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 13.5px;
  text-align: center;
  background: #fff;
  color: var(--ink);
}
table.data.rfq input:focus { outline: 2px solid var(--steel); border-color: var(--steel); }
table.data.rfq .rfq-item, table.data.rfq .rfq-desc { text-align: right; }
table.data.rfq .rfq-qty, table.data.rfq .rfq-cost, table.data.rfq .rfq-margin { max-width: 110px; }
table.data.rfq .rfq-unit { max-width: 80px; }
table.data.rfq .rfq-unitprice { font-weight: 700; color: var(--steel-dark); }
table.data.rfq .rfq-total { font-weight: 800; color: var(--slate-dark); }

body.client-view .col-cost,
body.client-view .col-margin { display: none !important; }

.rfq-summary {
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  margin-top: 12px;
  max-width: 520px;
  margin-inline-start: auto;
}
.rfq-summary .rrow {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line-soft);
  font-size: 14px;
}
.rfq-summary .rrow b { color: var(--slate-dark); }
.rfq-summary .rrow.subtotal { font-weight: 700; }
.rfq-summary .rrow.grand {
  border-bottom: none;
  font-size: 17px;
  font-weight: 800;
  color: var(--steel-dark);
  padding-top: 9px;
}
.rfq-summary .rrow.grand b { color: var(--steel-dark); }

/* Editable terms list */
.term-list { list-style: none; margin: 0; padding: 0; }
.term-list li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.term-list li:last-child { border-bottom: none; }
.term-list .term-input {
  flex: 1;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
}
.term-list .term-input:focus { outline: 2px solid var(--steel); border-color: var(--steel); }
.term-list .term-del { flex: 0 0 auto; }

/* ---------- Back to top ---------- */
#toTop {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: var(--steel);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  display: none;
  z-index: 60;
}
#toTop:hover { background: var(--slate-dark); }
#toTop.show { display: block; }

/* ---------- Footer ---------- */
footer.site {
  background: var(--slate);
  color: #d5e2ee;
  text-align: center;
  padding: 18px;
  font-size: 13px;
  margin-top: 40px;
}

/* ---------- Print / Word export ---------- */
@media print {
  .topbar, #toTop, .controls, .logo-controls, footer.site, .no-print, .print-this { display: none !important; }
  body { background: #fff; }
  .card, .kpi, .diagram-box { box-shadow: none; }
  h2.section { page-break-after: avoid; }
  table.data, .gantt table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
  .wrap { max-width: none; padding: 0; }
  .print-hide { display: none !important; }
}
body.exporting [data-export] { display: none !important; }
