/* Procurement module styles (spec 003, FR-027b). Every selector starts with .proc- (checks/procurement/module.js),
   except the token blocks on :root and the base rules. Tokens, borders, shadows, the slanted accent, hover lift, logos,
   header and home hub copy the IMPACT DC page template (DC/App/src/app.html, read only). Light / dark / system follow
   _shared/DESIGN.md. */

:root {
  --brand: #193FF9;
  --brand-strong: #0F2FD0;
  --brand-soft: #E3E8FF;
  --on-brand: #FFFFFF;
  --ink: #272727;
  --ink-secondary: #3D3D3D;
  --ink-muted: #5C5C5C;
  --surface: #FFFFFF;
  --surface-sunk: #EFEFEF;
  --surface-raised: #F6F6F6;
  --border: #E4E4E4;
  --border-strong: #8E8E8E;
  --ok: #1E7B46;
  --risk: #9A5B00;
  --late: #B42318;
  --shear: -16.7deg;
  --radius-sm: 2px;
  --radius-md: 4px;
  --font-sans: "Inter", "Segoe UI", system-ui, Arial, sans-serif;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, .18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #5C7BFF;
    --brand-strong: #3F63FF;
    --brand-soft: #1D2547;
    --on-brand: #0F1226;
    --ink: #F2F2F2;
    --ink-secondary: #D4D4D4;
    --ink-muted: #A3A3A3;
    --surface: #171717;
    --surface-sunk: #1B1B1B;
    --surface-raised: #212121;
    --border: #333333;
    --border-strong: #6B6B6B;
    --ok: #5BD197;
    --risk: #F5B94A;
    --late: #FF8A80;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --brand: #5C7BFF;
  --brand-strong: #3F63FF;
  --brand-soft: #1D2547;
  --on-brand: #0F1226;
  --ink: #F2F2F2;
  --ink-secondary: #D4D4D4;
  --ink-muted: #A3A3A3;
  --surface: #171717;
  --surface-sunk: #1B1B1B;
  --surface-raised: #212121;
  --border: #333333;
  --border-strong: #6B6B6B;
  --ok: #5BD197;
  --risk: #F5B94A;
  --late: #FF8A80;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

:root:lang(ar) {
  --font-sans: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 22px;
}

.proc-hide {
  display: none !important;
}

.proc-busy[hidden] {
  display: none;
}

/* ---------- Header: logo, page title stacked (Arabic over English), controls (DC top bar) ---------- */
.proc-top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.proc-home {
  display: block;
  flex: none;
}

.proc-logo {
  display: block;
  height: 34px;
  width: auto;
}

.proc-logo-dark {
  display: none;
}

:root[data-theme="dark"] .proc-logo-light {
  display: none;
}

:root[data-theme="dark"] .proc-logo-dark {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .proc-logo-light {
    display: none;
  }
  :root:not([data-theme="light"]) .proc-logo-dark {
    display: block;
  }
}

.proc-page-names {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding-inline-start: 16px;
  border-inline-start: 1px solid var(--border);
  line-height: 1.1;
}

.proc-page-names b {
  font-size: 15px;
  font-weight: 800;
}

.proc-page-names span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--ink-muted);
  text-transform: uppercase;
  text-align: start;
}

.proc-page-names[hidden] {
  display: none;
}

.proc-tools {
  margin-inline-start: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Language and theme switches: one row of 44 px touch targets (FR-027). The active option is filled. */
.proc-switch {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
}

.proc-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.proc-switch button + button {
  border-inline-start: 1px solid var(--border-strong);
}

.proc-switch button[aria-pressed="true"] {
  background: var(--brand);
  color: var(--on-brand);
}

.proc-flag {
  display: block;
  width: 20px;
  height: 13px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15);
}

.proc-ico {
  display: block;
  width: 18px;
  height: 18px;
}

/* Profile button: avatar, name with the role under it in small text, chevron; the menu holds the account and actions. */
.proc-prof {
  position: relative;
}

.proc-prof-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.proc-prof-btn:hover,
.proc-prof-btn[aria-expanded="true"] {
  border-color: var(--brand);
}

.proc-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
}

.proc-avatar .proc-ico {
  width: 20px;
  height: 20px;
}

.proc-who {
  display: flex;
  flex-direction: column;
  max-width: 200px;
  text-align: start;
  line-height: 1.2;
}

.proc-who b,
.proc-who .proc-role {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.proc-who b {
  font-size: 13px;
}

.proc-role {
  font-size: 11px;
  color: var(--ink-muted);
}

.proc-chev {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--ink-muted);
}

.proc-pmenu {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  z-index: 60;
  min-width: 260px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
}

.proc-phead {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.proc-phead b {
  font-size: 14px;
}

.proc-phead span {
  font-size: 12px;
  color: var(--ink-muted);
}

.proc-mi {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-secondary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.proc-mi:hover {
  background: var(--surface-raised);
  color: var(--brand);
}

/* ---------- Loading bar: a thin line under the header while a request runs (visible under reduced motion too) ---------- */
.proc-busy {
  position: fixed;
  top: 0;
  inset-inline: 0;
  z-index: 95;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: proc-busy 1s linear infinite;
}

@keyframes proc-busy {
  from {
    background-position: -40% 0;
  }
  to {
    background-position: 140% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .proc-busy {
    animation: none;
    background: var(--brand);
    opacity: .6;
  }
}

/* ---------- Main area and footer ---------- */
.proc-main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  box-sizing: border-box;
}

.proc-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--ink-muted);
}

/* ---------- Section headings: a rule under the title with the slanted brand accent (DC .section-t) ---------- */
.proc-section-t,
.proc-card > h2 {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  line-height: 22px;
  font-weight: 800;
}

.proc-section-t::before,
.proc-card > h2::before {
  content: "";
  position: absolute;
  bottom: -1px;
  inset-inline-start: 0;
  width: 30px;
  height: 3px;
  background: var(--brand);
  transform: skewX(var(--shear));
}

.proc-section-t {
  margin-top: 24px;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--ink-secondary);
}

/* ---------- Cards and forms: 1 px border, raised surface, shadow (DC .card / .mod) ---------- */
.proc-card {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.proc-card p {
  margin: 0 0 8px;
  color: var(--ink-secondary);
}

.proc-form {
  display: grid;
  gap: 12px;
}

.proc-field {
  display: grid;
  gap: 4px;
  font-size: 14px;
  color: var(--ink-secondary);
}

.proc-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.proc-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  border-color: var(--brand);
}

.proc-input:disabled {
  background: var(--surface-sunk);
  color: var(--ink-muted);
  cursor: not-allowed;
}

/* ---------- Buttons: DC hover lift (mouse only), reduced motion keeps the colour change ---------- */
.proc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--on-brand);
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform .25s ease, box-shadow .25s ease, background-color .15s ease, border-color .15s ease, color .15s ease;
}

.proc-btn:hover {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
}

.proc-btn:focus-visible,
.proc-mi:focus-visible,
.proc-switch button:focus-visible,
.proc-prof-btn:focus-visible,
.proc-mod:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.proc-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.proc-btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

.proc-ghost {
  color: var(--brand);
  background: transparent;
  border: 1px solid var(--brand);
}

.proc-ghost:hover {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--brand);
}

.proc-qm {
  margin-inline-start: 6px;
  font-size: 12px;
  font-weight: 600;
  opacity: .85;
}

@media (hover: hover) {
  .proc-btn:not([disabled]):hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 22px color-mix(in srgb, var(--brand) 32%, transparent);
  }
  .proc-mod:hover,
  .proc-hk:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 28px color-mix(in srgb, var(--brand) 28%, transparent);
  }
  .proc-mod:hover {
    border-color: var(--brand);
  }
}

@media (prefers-reduced-motion: reduce) {
  .proc-btn,
  .proc-mod,
  .proc-hk,
  .proc-prof-btn,
  .proc-mi {
    transition: none;
  }
  .proc-btn:not([disabled]):hover,
  .proc-mod:hover,
  .proc-hk:hover {
    transform: none;
  }
}

.proc-error {
  border: 1px solid var(--late);
}

.proc-error h2 {
  color: var(--late);
}

.proc-msg {
  margin: 0;
  font-size: 14px;
  color: var(--late);
}

.proc-status {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 14px;
  color: var(--ink-muted);
}

/* ---------- Home hub (DC hub): greeting, module cards, quick actions, at-a-glance tiles ---------- */
.proc-hello {
  margin: 0;
  font-size: 26px;
  line-height: 34px;
  font-weight: 800;
}

.proc-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.proc-mods {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}

.proc-mod {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 150px;
  padding: 16px;
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}

/* The slanted accent on the top edge (DC .mod::before). */
.proc-mod::before {
  content: "";
  position: absolute;
  top: -1px;
  inset-inline-start: 16px;
  width: 30px;
  height: 4px;
  background: var(--brand);
  transform: skewX(var(--shear));
}

.proc-tile {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--brand-strong);
  background: var(--brand-soft);
  border-radius: var(--radius-md);
}

.proc-mod b {
  font-size: 16px;
}

.proc-md {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-muted);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.proc-mgo {
  margin-top: auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
}

.proc-qacts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.proc-hks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.proc-hk {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: transform .25s ease, box-shadow .25s ease;
}

.proc-hk b {
  font-size: 26px;
  line-height: 32px;
  font-variant-numeric: tabular-nums;
}

.proc-hk span {
  font-size: 12px;
  color: var(--ink-muted);
}

/* ---------- Sign-in: DC login layout (brand panel and form box) ---------- */
.proc-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
  gap: 24px;
  align-items: center;
  min-height: calc(100vh - 160px);
}

.proc-login-brand {
  display: grid;
  justify-items: center;
  gap: 24px;
  padding: 24px;
}

.proc-login-brand .proc-logo {
  height: 96px;
}

.proc-welcome {
  margin: 0;
  font-size: 22px;
  line-height: 30px;
  font-weight: 800;
  text-align: center;
}

.proc-login-hint {
  margin: 0;
  font-size: 14px;
  color: var(--ink-muted);
  text-align: center;
}

.proc-login-box {
  margin: 0;
  padding: 32px;
}

.proc-login-box > .proc-logo {
  height: 30px;
  justify-self: start;
}

@media (max-width: 760px) {
  .proc-login {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
  }
  .proc-login-brand {
    display: none;
  }
}

/* Wide tables scroll inside their own frame, never the page (FR-027). */
.proc-scroll {
  max-width: 100%;
  overflow-x: auto;
}

/* Tables inside a scroll frame fill its width, so empty columns keep a usable size (a click on a row
   must land on a cell, and the label column must not collapse). */
.proc-scroll table {
  width: 100%;
  border-collapse: collapse;
}

.proc-scroll th,
.proc-scroll td {
  padding: 4px 8px;
  vertical-align: middle;
}

.proc-scroll th {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-muted);
  text-align: start;
  border-bottom: 1px solid var(--border-strong);
}

.proc-scroll td {
  border-bottom: 1px solid var(--border);
}

.proc-scroll td:first-child {
  min-width: 160px;
}

/* ---------- Tree (registry) and small controls ---------- */
.proc-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.proc-tree .proc-tree {
  margin-inline-start: 12px;
  padding-inline-start: 16px;
  border-inline-start: 2px solid var(--brand-soft);
}

.proc-node {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 0;
}

.proc-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 14px;
  color: var(--brand);
}

.proc-chip {
  padding: 2px 8px;
  font-size: 12px;
  color: var(--ink-secondary);
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
}

.proc-toggle {
  min-width: 44px;
  padding: 4px 8px;
}

/* Import preview KPIs. */
.proc-kpi {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
  padding: 8px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--brand);
  border-radius: var(--radius-sm);
  transition: transform .25s ease, box-shadow .25s ease;
}

.proc-kpi b {
  font-size: 18px;
}

/* Rows that open a detail panel, and numbers aligned to the end of the cell. */
.proc-pick {
  cursor: pointer;
}

.proc-pick:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.proc-num {
  text-align: end;
  font-family: ui-monospace, Consolas, monospace;
  white-space: nowrap;
}

/* ---------- Small screens: the profile name gives way to the avatar and the controls fit ---------- */
@media (max-width: 720px) {
  .proc-top {
    padding: 8px 12px;
  }
  .proc-page-names span {
    display: none;
  }
  .proc-who,
  .proc-chev {
    display: none;
  }
  .proc-prof-btn {
    padding: 4px;
  }
  .proc-main {
    padding: 12px;
  }
  .proc-tools {
    gap: 6px;
  }
  .proc-switch button {
    padding: 0 8px;
  }
}

/* ---------- Print: logos greyscale, the controls and the loading bar are not printed ---------- */
@media print {
  .proc-logo {
    filter: grayscale(1);
  }
  .proc-tools,
  .proc-busy,
  .proc-foot {
    display: none !important;
  }
}
