@import url('https://fonts.googleapis.com/css2?family=League+Spartan:wght@500;600;700;800&family=Instrument+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

/* ==========================================================================
   Contrast Trading contract tracker: design tokens
   Colour has a job. Contrast red = the one primary action and "done".
   Orange = waiting on someone / due soon. Green = paid, balanced, approved.
   Everything else stays on the brand grey and near-black so those three read.
   ========================================================================== */
:root {
  /* Surfaces & ink (brand sheet neutrals) */
  --paper: #f3f3f1;          /* page ground */
  --paper-2: #ecebe8;        /* table heads, quiet fills */
  --sheet: #ffffff;          /* cards, inputs */
  --ink: #171414;            /* text, wordmark */
  --ink-soft: #5f5955;       /* secondary text (5.9:1 on white) */
  --ink-faint: #8a837e;      /* placeholders, disabled */
  --rule: #d6d3cf;           /* hairlines (UX direction) */
  --rule-strong: #c6c1bb;    /* input borders */

  /* Brand roles */
  --red: #aa2003;            /* primary action, done stages */
  --red-hover: #8b1a02;
  --red-tint: #f7e6e1;
  --orange: #a85300;         /* waiting text (AA on white); brand #D46E00 for fills */
  --orange-fill: #d46e00;
  --orange-tint: #fbecd9;
  --green: #2f7a4c;
  --green-tint: #e2f1e7;
  --blue: #2b5d8a;           /* information only */
  --blue-tint: #e5eef6;

  /* Type */
  --font-display: "League Spartan", "Futura", "Century Gothic", "Trebuchet MS", sans-serif;
  --font-body: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --text-xs: 12px;
  --text-sm: 13.5px;
  --text-md: 15px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 30px;

  /* Shape */
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow-pop: 0 18px 40px -12px rgba(23, 20, 20, 0.28), 0 4px 12px rgba(23, 20, 20, 0.08);

  /* Legacy names still used by page scripts and inline styles */
  --bg: var(--paper);
  --surface: var(--sheet);
  --border: var(--rule);
  --border-strong: var(--rule-strong);
  --text: var(--ink);
  --text-main: var(--ink);
  --text-muted: var(--ink-soft);
  --primary: var(--red);
  --primary-hover: var(--red-hover);
  --primary-light: var(--red-tint);
  --brand-orange: var(--orange-fill);
  --brand-dark: var(--ink);
  --danger: #b42318;
  --success: var(--green);
  --warning: var(--orange);
  --shadow-sm: none;
  --shadow-card: none;
  --shadow-elevated: var(--shadow-pop);
}

* { box-sizing: border-box; }
html { overflow-x: hidden; max-width: 100vw; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: var(--text-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  max-width: 100vw;
}

h1, h2, h3, .brand-title { font-family: var(--font-display); letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--text-2xl); line-height: 1.1; margin: 0 0 6px; font-weight: 700; color: var(--ink); }
h2 { font-size: var(--text-lg); line-height: 1.2; margin: 0 0 12px; font-weight: 700; color: var(--ink); }
h3 { font-weight: 700; }
.subtitle { color: var(--ink-soft); margin: 0 0 20px; font-size: var(--text-sm); line-height: 1.45; max-width: 72ch; }

/* The logo's striped sun, used once per page under the title */
.toolbar h1::after, .page-title::after {
  content: ""; display: block; width: 72px; height: 13px; margin-top: 8px;
  background:
    linear-gradient(var(--red), var(--red)) 0 0 / 100% 3px no-repeat,
    linear-gradient(var(--red), var(--red)) 6px 5px / 60px 3px no-repeat,
    linear-gradient(var(--red), var(--red)) 14px 10px / 44px 3px no-repeat;
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--red-hover); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.num, .money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Icons (inline SVG from ui.js) */
.icon { width: 1.1em; height: 1.1em; flex: none; display: inline-block; vertical-align: -0.17em; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Top navigation ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px;
  background: var(--sheet); border-bottom: 1px solid var(--rule);
  padding: 10px 24px; position: sticky; top: 0; z-index: 40;
}
.topbar .brand-wrap { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.topbar .brand-logo { height: 36px; width: auto; display: block; }
.topbar .brand-text { display: flex; flex-direction: column; }
.topbar .brand-title { font-weight: 700; font-size: 16px; color: var(--ink); line-height: 1.1; }
.topbar .brand-sub { font-weight: 500; color: var(--ink-soft); font-size: 12px; }
.topbar nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; row-gap: 6px; }
.topbar nav > a { color: var(--ink); font-weight: 500; font-size: 14.5px; padding: 6px 10px; border-radius: var(--radius-sm); }
.topbar nav > a:hover { background: var(--paper); text-decoration: none; color: var(--ink); }
.topbar nav > a.active { color: var(--red); font-weight: 600; box-shadow: inset 0 -2px 0 var(--red); border-radius: 0; }
.topbar .who { color: var(--ink-soft); font-size: 13px; margin: 0 6px 0 8px; }

.nav-bell-link {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  background: transparent; color: var(--ink); border: 1px solid var(--rule); margin-left: 6px;
}
.nav-bell-link:hover { background: var(--paper); color: var(--red); }
.nav-bell-icon { display: inline-flex; line-height: 1; }
.nav-bell-badge {
  position: absolute; top: -5px; right: -5px; background: var(--orange-fill); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; line-height: 18px;
  border-radius: 9px; text-align: center; padding: 0 4px; font-variant-numeric: tabular-nums;
}
.nav-bell-badge.hidden { display: none; }
.nav-bell-wrap { position: relative; display: inline-flex; }
.nav-bell-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0; left: auto;
  width: min(380px, calc(100vw - 20px)); max-width: calc(100vw - 20px);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); z-index: 1000; display: flex; flex-direction: column; overflow: hidden;
}
.bell-dropdown-header { padding: 12px 16px; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; align-items: center; }
.bell-dropdown-header h4 { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); }
.bell-dropdown-header .bell-pill { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.bell-dropdown-body { max-height: 420px; overflow-y: auto; padding: 0; margin: 0; list-style: none; }
.bell-dropdown-item { padding: 11px 14px; border-bottom: 1px solid var(--rule); display: flex; gap: 10px; align-items: flex-start; text-decoration: none; color: inherit; }
.bell-dropdown-item:hover { background: var(--paper); text-decoration: none; }
.bell-dropdown-body li:last-child .bell-dropdown-item { border-bottom: none; }
.bell-item-icon { line-height: 1; margin-top: 2px; flex-shrink: 0; color: var(--ink-soft); }
.bell-item-icon.tone-ok { color: var(--green); }
.bell-item-icon.tone-back { color: var(--red); }
.bell-item-icon.tone-wait { color: var(--orange); }
.bell-item-content { flex: 1; min-width: 0; }
.bell-item-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 2px; }
.bell-item-title { font-weight: 600; font-size: 13.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bell-item-subtitle { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bell-item-detail { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; line-height: 1.4; }
.bell-item-meta { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }
.bell-dropdown-footer { padding: 10px 14px; border-top: 1px solid var(--rule); text-align: center; font-size: 13.5px; }
.bell-dropdown-footer a { font-weight: 600; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 28px auto; padding: 0 24px; }
.dashboard-layout { max-width: 1600px; margin: 28px auto; padding: 0 24px; }
.dashboard-main { width: 100%; }

.drawer-overlay { position: fixed; inset: 0; background: rgba(23, 20, 20, 0.4); z-index: 1000; }
.dashboard-drawer {
  position: fixed; top: 0; right: -440px; width: 400px; max-width: 92vw; height: 100vh;
  background: var(--sheet); box-shadow: var(--shadow-pop); z-index: 1001;
  display: flex; flex-direction: column; transition: right 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.dashboard-drawer.open { right: 0; }

.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 640px; }
.table-scroll th, .table-scroll td { white-space: nowrap; }

.card {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-lg);
  padding: 24px; margin-bottom: 20px; width: 100%; max-width: 100%;
  overflow-wrap: break-word; word-break: break-word;
}

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; width: 100%; max-width: 100%; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; max-width: 100%; }
.form-field.span-2 { grid-column: span 2; }
.form-field.span-3 { grid-column: span 3; }
.form-field label { font-weight: 600; font-size: 13.5px; color: var(--ink); overflow-wrap: break-word; }
.form-field .hint { font-size: 12.5px; color: var(--ink-soft); line-height: 1.4; overflow-wrap: break-word; }

input, select, textarea, button { font-family: inherit; font-size: var(--text-md); }
input, select, textarea {
  width: 100%; max-width: 100%; min-width: 0; padding: 9px 12px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  background: var(--sheet); color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
select { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
select option { white-space: normal; }
input[type="file"] { max-width: 100%; min-width: 0; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 20, 20, 0.1); outline: none; }
input:disabled, select:disabled, textarea:disabled, input[readonly] { background: var(--paper); color: var(--ink-soft); border-color: var(--rule); }
input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--red); }
textarea { resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); }
.checkbox-row input { width: auto; cursor: pointer; }

/* ---------- Buttons ---------- */
button, .btn-primary, .btn-secondary, .btn-danger, .btn-success {
  cursor: pointer; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-weight: 600; font-size: 14.5px; line-height: 1.2;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  text-decoration: none;
}
a.btn-primary, a.btn-secondary, a.btn-danger, a.btn-success { text-decoration: none; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-hover); border-color: var(--red-hover); color: #fff; text-decoration: none; }
.btn-secondary { background: var(--sheet); color: var(--ink); border-color: var(--rule-strong); }
.btn-secondary:hover { background: var(--paper); border-color: var(--ink-faint); color: var(--ink); text-decoration: none; }
.btn-danger { background: var(--sheet); color: var(--danger); border-color: #e3b4ad; }
.btn-danger:hover { background: #fbeceb; border-color: var(--danger); color: var(--danger); text-decoration: none; }
.btn-danger.solid, .ui-dialog .btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger.solid:hover, .ui-dialog .btn-danger:hover { background: #8f1c13; color: #fff; }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #24603b; color: #fff; text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: 13.5px; border-radius: 6px; }
button:disabled, .btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.btn-group { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.icon-btn { padding: 0; width: 32px; height: 32px; border-radius: 50%; background: transparent; border: 1px solid var(--rule); color: var(--ink); }
.icon-btn:hover { background: var(--paper); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--rule); font-size: 14px; }
th { background: var(--paper-2); color: var(--ink-soft); font-weight: 600; font-size: 13px; border-top: 1px solid var(--rule); white-space: nowrap; }
tr:hover td { background: #faf9f7; }
td.money, th.money, td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
.money .cur { color: var(--ink-soft); font-size: 0.86em; margin-left: 4px; font-weight: 500; }

/* ---------- Status pills: one vocabulary, colour by who holds it ---------- */
.badge, .status-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1.5; white-space: nowrap; border: 1px solid transparent;
}
.badge-draft, .st-draft { background: var(--paper-2); color: var(--ink-soft); }
.badge-pending, .st-wait { background: var(--orange-tint); color: var(--orange); }
.badge-approved, .st-ok { background: var(--green-tint); color: var(--green); }
.badge-rejected, .st-back { background: var(--red-tint); color: var(--red); }
.badge-warning { background: var(--orange-tint); color: var(--orange); }
.st-closed { background: var(--paper-2); color: var(--ink); }
.st-info { background: var(--blue-tint); color: var(--blue); }
.badge-party-code {
  background: var(--paper); color: var(--ink); border: 1px solid var(--rule);
  font-variant-numeric: tabular-nums; font-size: 12.5px; font-weight: 600; border-radius: 5px; padding: 1px 7px;
}

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: end; }
.filters .form-field { min-width: 140px; }
.toolbar { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: var(--text-sm); font-weight: 500; border: 1px solid transparent; }
.alert-error { background: var(--red-tint); color: #7d1702; border-color: #ecc4ba; }
.alert-success { background: var(--green-tint); color: #1f5434; border-color: #bfdcc9; }
.alert-info { background: var(--blue-tint); color: #1f4466; border-color: #c7d9ea; }
.alert-warning { background: var(--orange-tint); color: #7a3d00; border-color: #efcfa6; }

.empty-state { text-align: center; color: var(--ink-soft); padding: 40px 0; }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; justify-content: space-between; align-items: center; gap: 6px 16px; flex-wrap: wrap; padding: 11px 0; border-bottom: 1px solid var(--rule); }
.doc-list li:last-child { border-bottom: none; }
.doc-meta { color: var(--ink-soft); font-size: 13px; }

.audit-list { list-style: none; margin: 0; padding: 0; }
.audit-list li { padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: 13.5px; overflow-wrap: break-word; }
.audit-list li:last-child { border-bottom: none; }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }

/* ---------- Modals & in-page dialogs ---------- */
.modal-overlay, .ui-dialog-overlay {
  position: fixed; inset: 0; background: rgba(23, 20, 20, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 999; padding: 16px;
}
.ui-dialog-overlay { z-index: 10000; }
.modal-box, .ui-dialog {
  background: var(--sheet); border-radius: var(--radius-lg); padding: 24px; width: 460px; max-width: 100%;
  max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: var(--shadow-pop); border: 1px solid var(--rule);
}
.ui-dialog h2 { font-size: 20px; margin: 0 0 8px; }
.ui-dialog p { margin: 0; color: var(--ink-soft); font-size: var(--text-md); white-space: pre-line; }
.ui-dialog .btn-row { justify-content: flex-end; margin-top: 22px; }
@media (prefers-reduced-motion: no-preference) {
  .ui-dialog, .modal-box { animation: dialogIn 0.16s ease-out; }
  @keyframes dialogIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Toasts: what just happened, bottom of the screen */
.ui-toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10001; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.ui-toast {
  display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; border-radius: 999px;
  padding: 10px 18px; font-size: 14.5px; font-weight: 500; box-shadow: var(--shadow-pop);
}
.ui-toast.tone-error { background: #7d1702; }
.ui-toast .icon { color: #fff; }

@media (max-width: 800px) {
  .form-grid, .form-grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .form-field.span-2, .form-field.span-3 { grid-column: span 1; }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; margin: 16px auto; }
  .card { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .topbar .who { display: none; }
  h1 { font-size: 24px; }
  .toolbar { align-items: stretch; }
  .btn-group { flex-direction: column; align-items: stretch; }
  .btn-group > a { display: flex; }
  .btn-group > button, .btn-group > a > button { width: 100%; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .form-field { min-width: 0; width: 100%; }
  .filters button { width: 100%; }
  .btn-row { flex-direction: column; }
  .btn-row button { width: 100%; }
  .modal-box { padding: 18px; }
  button, input, select { min-height: 42px; }
  .btn-sm { min-height: 34px; }
  .doc-list li, .doc-list li > span { width: 100%; }
}

/* ---------- Sign-in ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--paper); }
.login-card { width: 100%; max-width: 400px; padding: 32px; border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--sheet); }
.login-card h1 { font-size: 26px; margin: 0 0 4px; text-align: center; }
.login-card .subtitle { text-align: center; margin: 0 auto 24px; }

/* ==========================================================================
   Page components (payment terms, financial summary, ledger, audit, quick stats)
   ========================================================================== */
/* Payment schedule, financial summary */
.balance-banner {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: var(--text-sm); font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.balance-banner.balanced { background: var(--green-tint); border: 1px solid #bfdcc9; color: #1f5434; }
.balance-banner.unbalanced { background: var(--orange-tint); border: 1px solid #efcfa6; color: #7a3d00; }

.milestone-table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--sheet); margin-bottom: 14px; }
.milestone-table-wrap::-webkit-scrollbar, .table-scroll::-webkit-scrollbar { height: 8px; }
.milestone-table-wrap::-webkit-scrollbar-track, .table-scroll::-webkit-scrollbar-track { background: var(--paper-2); border-radius: 4px; }
.milestone-table-wrap::-webkit-scrollbar-thumb, .table-scroll::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 4px; }
.milestone-table { width: 100%; min-width: 1060px; border-collapse: collapse; margin-bottom: 0; }
.milestone-table th { background: var(--paper-2); padding: 9px 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; }
.milestone-table td { padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; font-variant-numeric: tabular-nums; }
.milestone-table tr:last-child td { border-bottom: none; }
.milestone-table input, .milestone-table select { width: 100%; min-width: 0; padding: 6px 8px; font-size: 14px; }
.milestone-table input[type="number"] { -moz-appearance: textfield; text-align: right; }
.milestone-table input[type="number"]::-webkit-outer-spin-button, .milestone-table input[type="number"]::-webkit-inner-spin-button { margin: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0; margin-bottom: 20px; border-top: 2px solid var(--ink); }
.metric-box { background: transparent; border: 0; border-right: 1px solid var(--rule); border-radius: 0; padding: 14px 18px 10px 0; margin-right: 18px; }
.metric-box:last-child { border-right: 0; margin-right: 0; }
.metric-title { font-size: 13.5px; color: var(--ink-soft); font-weight: 600; margin-bottom: 6px; }
.metric-value { font-family: var(--font-display); font-size: 25px; line-height: 1.1; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.metric-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; line-height: 1.4; }
.metric-value.tone-revenue, .metric-value.tone-procurement { color: var(--ink); }

/* Dashboard financial summary: one block per currency */
.fin-scope { font-size: 13px; color: var(--ink-soft); margin: 0 0 14px; }
.fin-currency + .fin-currency { padding-top: 18px; margin-top: 6px; }
.fin-currency-head { font-family: var(--font-display); font-size: 20px; margin: 0 0 10px; display: flex; align-items: baseline; gap: 10px; }
.fin-currency-head span { font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--ink-soft); letter-spacing: 0; }
.fin-currency .metric-grid { margin-bottom: 8px; }
.fin-notes { font-size: 13px; color: var(--ink-soft); margin: 0 0 12px; }
.fin-empty { font-size: 14px; color: var(--ink-soft); margin: 8px 0 4px; }

.tax-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tax-badge-vat { background: var(--blue-tint); color: var(--blue); }
.tax-badge-wht { background: var(--orange-tint); color: var(--orange); }

/* ==========================================================================
   Responsive Breakpoints & Mobile Adaptability
   ========================================================================== */
@media (max-width: 960px) {
  .container { padding: 0 16px; margin: 16px auto; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-field.span-3 { grid-column: span 2; }
}

@media (max-width: 680px) {
  .container { padding: 0 12px; margin: 12px auto; max-width: 100%; box-sizing: border-box; }
  .card { padding: 16px 14px; max-width: 100%; box-sizing: border-box; }
  .form-grid, .form-grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .form-field.span-2, .form-field.span-3 { grid-column: span 1; }
  .toolbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .toolbar .btn-group, .toolbar > div:last-child { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .balance-banner { flex-direction: column; align-items: flex-start; gap: 6px; }
  .btn-row { flex-direction: column; width: 100%; gap: 8px; }
  .btn-row button, .btn-row a, .btn-row a button { width: 100%; }
  .modal-box { width: calc(100% - 24px); max-height: 90vh; overflow-y: auto; padding: 18px 14px; margin: 12px; }
  .topbar { padding: 8px 14px; }
  .topbar nav { gap: 10px; }
  .metric-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Phase 2: Floating Alerts, Field Error Outlines & Submission Modals
   ========================================================================== */
.floating-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: #fff;
  border: 1.5px solid var(--danger);
  box-shadow: 0 12px 28px rgba(220, 38, 38, 0.2), 0 4px 10px rgba(0, 0, 0, 0.08);
  padding: 12px 22px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  animation: toastSlideUp 0.25s ease-out;
  max-width: 90vw;
}

@keyframes toastSlideUp {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.floating-toast button {
  background: none;
  border: none;
  color: var(--red);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.field-error-outline {
  border-color: var(--danger) !important;
  background-color: var(--red-tint) !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15) !important;
}

.field-error-hint {
  color: var(--danger);
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
  display: block;
}

.success-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--green-tint);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 16px;
}

/* ==========================================================================
   Responsive Filter Grid & Mobile Adaptability
   ========================================================================== */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filters .form-field {
  min-width: 0;
  max-width: 100%;
}
.filters select,
.filters input {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.filters .form-field:first-child {
  min-width: 0;
}
@media (min-width: 1200px) {
  .filters {
    grid-template-columns: 2.2fr repeat(5, 1fr) auto;
  }
}
@media (max-width: 860px) {
  .filters {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .filters .form-field:first-child {
    grid-column: span 2;
  }
}
@media (max-width: 540px) {
  .filters {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .filters .form-field:first-child {
    grid-column: span 1;
  }
  .filters button, .filters #apply-filters {
    width: 100%;
  }
}

/* Financial Dashboard Bar Party/Quarter/Type Filter Constraints */
#fin-f-quarter,
#fin-f-party,
#fin-f-type {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  text-overflow: ellipsis;
}
@media (max-width: 860px) {
  #fin-f-party {
    max-width: 220px;
  }
}
@media (max-width: 580px) {
  #fin-f-quarter,
  #fin-f-party,
  #fin-f-type {
    width: 100%;
    max-width: 100%;
  }
}

/* ==========================================================================
   Settlement Modal & Payment Ledger Refinements
   ========================================================================== */
#settle-payment-modal .modal-box {
  width: 620px;
  max-width: min(620px, calc(100vw - 32px));
  padding: 28px 32px;
  border-radius: var(--radius-lg);
  box-sizing: border-box;
}
#sp-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  row-gap: 16px;
  column-gap: 18px;
  width: 100%;
  box-sizing: border-box;
}
#sp-form-grid .form-field {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
#sp-form-grid .form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
}
#sp-form-grid .form-field input,
#sp-form-grid .form-field select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 9px 12px;
  font-size: 13px;
  border-radius: 8px;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  box-sizing: border-box;
}
#sp-form-grid .form-field input:focus,
#sp-form-grid .form-field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 20, 20, 0.1);
}
#sp-form-grid .hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  word-break: break-word;
  overflow-wrap: break-word;
}

@media (max-width: 680px) {
  #settle-payment-modal .modal-box {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    padding: 20px 16px;
    margin: 12px auto;
  }
  #sp-form-grid {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 14px;
  }
  #sp-form-grid .form-field.span-2 {
    grid-column: span 1;
  }
  #sp-form-grid .form-field label {
    font-size: 12px;
  }
  #settle-payment-form .btn-row {
    flex-direction: column;
    width: 100%;
  }
  #settle-payment-form .btn-row button {
    width: 100%;
  }
}

/* ==========================================================================
   Change Requests Card & Form Layout
   ========================================================================== */
#change-request-card {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
#cr-form {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
#cr-form .form-field {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
#cr-form select,
#cr-form input,
#cr-form textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
#cr-form select {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
#cr-form button,
#cr-submit-btn {
  width: 100%;
  min-height: 42px;
}

/* Executive Financial Typography: Tabular Numerals */
.metric-value,
.table-scroll td:nth-child(5),
.tb-net,
.tb-base,
.tb-vat-amt,
.tb-wht-amt,
.milestone-table td:nth-child(4),
.milestone-table td:nth-child(5),
.milestone-table td:nth-child(6) {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* Password visibility outline eye toggle */
.password-toggle-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background-color 0.15s ease;
  line-height: 1;
}

.password-toggle-btn:hover {
  color: var(--text);
  background: rgba(15, 23, 42, 0.06);
}

.password-toggle-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.password-toggle-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  display: block;
}

/* Audit log entity badges & action tags */
.entity-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  text-decoration: none;
  line-height: 1.35;
  max-width: 320px;
  vertical-align: middle;
}
.entity-badge:hover {
  text-decoration: none;
}
.entity-badge .entity-icon {
  font-size: 13px;
  flex-shrink: 0;
}
.entity-badge .entity-code {
  font-weight: 600;
  flex-shrink: 0;
}
.entity-badge .entity-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entity-contract {
  background: var(--blue-tint);
  border: 1px solid #c7d9ea;
  color: var(--blue);
}
.entity-contract:hover {
  background: var(--blue-tint);
}
.entity-user {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink);
}
.entity-party {
  background: var(--green-tint);
  border: 1px solid #bfdcc9;
  color: var(--green);
}
.entity-party:hover {
  background: var(--green-tint);
}
.badge-role {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--paper-2);
  color: var(--ink);
}
.action-tag {
  display: inline-block;
  font-weight: 600;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 4px;
}
.action-tag.action-general {
  background: var(--paper-2);
  color: var(--ink);
}
.action-tag.action-user {
  background: var(--paper-2);
  color: var(--ink);
}
.action-tag.action-party {
  background: var(--blue-tint);
  color: var(--blue);
}
.action-tag.action-success {
  background: var(--green-tint);
  color: var(--green);
}
.action-tag.action-danger {
  background: var(--red-tint);
  color: var(--red);
}

/* Phase 3: Contract Entry Quick-Stats & Counterparty View Modal */
.quick-stats-ribbon {
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.quick-stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.quick-stats-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-dark);
}
.quick-stats-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  background: var(--green-tint);
  color: var(--green);
  border: 1px solid #bfdcc9;
}
.quick-stats-badge.sync-warning {
  background: var(--orange-tint);
  color: var(--orange);
  border-color: #efcfa6;
}
.quick-stats-grid {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.stat-pill-item {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 120px;
  flex: 1;
}
.stat-pill-gross {
  background: var(--blue-tint);
  border-color: #c7d9ea;
}
.stat-pill-gross .stat-pill-value {
  color: var(--blue);
  font-weight: 700;
}
.stat-pill-wht {
  background: var(--orange-tint);
  border-color: #efcfa6;
}
.stat-pill-wht .stat-pill-value {
  color: var(--orange);
}
.stat-pill-net {
  background: var(--green-tint);
  border-color: #bfdcc9;
  box-shadow: 0 1px 2px rgba(16, 185, 129, 0.1);
}
.stat-pill-net .stat-pill-value {
  color: var(--green);
  font-size: 15px;
  font-weight: 800;
}
.stat-pill-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  margin-bottom: 2px;
}
.stat-pill-value {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}
.stat-pill-math {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-faint);
  padding: 0 2px;
}
.quick-stats-footer {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.party-info-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
}
.info-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}
.info-card-val {
  font-size: 13px;
  color: var(--text-main);
  word-break: break-word;
}





/* Segmented switches (lists and tabs): the selected one is ink, never the action red */
.seg { gap: 0 !important; display: inline-flex !important; border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); overflow: hidden; flex-wrap: wrap; }
.seg > button, .seg > button.btn-primary, .seg > button.btn-secondary { border: 0; border-radius: 0; background: var(--sheet); color: var(--ink); font-weight: 500; }
.seg > button + button { border-left: 1px solid var(--rule-strong); }
.seg > button.btn-primary { background: var(--ink); color: #fff; font-weight: 600; }
.seg > button.btn-secondary:hover { background: var(--paper); }

/* Hidden always wins over component display rules */
[hidden] { display: none !important; }

/* Value-and-tax strip: neutral boxes, only the net result carries colour */
.quick-stats-ribbon { background: var(--paper); border-color: var(--rule); }
.stat-pill-item, .stat-pill-gross, .stat-pill-wht { background: var(--sheet); border-color: var(--rule); box-shadow: none; }
.stat-pill-gross .stat-pill-value { color: var(--ink); }
.stat-pill-wht .stat-pill-value { color: var(--orange); }
.stat-pill-net { background: var(--green-tint); border-color: #bfdcc9; box-shadow: none; }
.stat-pill-value { font-size: 15px; }
.stat-pill-label { font-size: 12.5px; letter-spacing: 0; }
.topbar .who { line-height: 1.25; text-align: right; }
#fin-refresh-btn { padding: 9px 14px; font-size: 14.5px; }

.milestone-table td { white-space: nowrap; }
.milestone-table td input[type="text"], .milestone-table td input:not([type]) { min-width: 160px; }

@media (max-width: 680px) {
  .metric-grid { grid-template-columns: minmax(0, 1fr); }
  .metric-box { border-right: 0; margin-right: 0; border-bottom: 1px solid var(--rule); padding-right: 0; }
  .metric-box:last-child { border-bottom: 0; }
  .topbar nav > a { padding: 6px 8px; font-size: 14px; }
}

/* ---------- Journey strip (stripes from the logo's sun) ---------- */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.journey-card { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 18px 22px 16px; margin-bottom: 20px; overflow-x: auto; }
.journey { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 8px; min-width: 680px; }
.jstage { display: flex; flex-direction: column; gap: 9px; }
.jbars { display: flex; flex-direction: column; gap: 4px; }
.jbars i { display: block; height: 7px; border-radius: 4px; background: var(--rule); }
.jbars i:nth-child(2) { margin-inline: 6%; }
.jbars i:nth-child(3) { margin-inline: 14%; }
.jstage b { font-size: 14.5px; font-weight: 600; line-height: 1.25; display: block; }
.jstage small { display: block; color: var(--ink-soft); font-size: 12.5px; line-height: 1.4; min-height: 1.4em; }
.js-done .jbars i { background: var(--red); }
.js-now .jbars i { background: var(--orange-fill); }
.js-now b { color: var(--orange); }
.js-back .jbars i { background: var(--red); opacity: 0.35; }
.js-back b { color: var(--red); }
.js-skip .jbars i { background: repeating-linear-gradient(90deg, var(--rule) 0 6px, transparent 6px 10px); }
.js-skip b, .js-todo b { color: var(--ink-soft); font-weight: 500; }
@media (prefers-reduced-motion: no-preference) {
  .journey .js-done .jbars i, .journey .js-now .jbars i { transform-origin: left center; animation: jfill 600ms cubic-bezier(.2,.7,.2,1) both; }
  .journey .jstage:nth-child(2) .jbars i { animation-delay: 80ms; }
  .journey .jstage:nth-child(3) .jbars i { animation-delay: 160ms; }
  .journey .jstage:nth-child(4) .jbars i { animation-delay: 240ms; }
  .journey .jstage:nth-child(5) .jbars i { animation-delay: 320ms; }
  .journey .jstage:nth-child(6) .jbars i { animation-delay: 400ms; }
  @keyframes jfill { from { transform: scaleX(0.15); } to { transform: scaleX(1); } }
}

/* Compact strip for list rows */
.journey-compact { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 13.5px; }
.jc-bars { display: inline-flex; gap: 2px; }
.jc-bars i { width: 9px; height: 5px; border-radius: 3px; background: var(--rule); display: block; }
.jc-bars i.js-done { background: var(--red); }
.jc-bars i.js-now { background: var(--orange-fill); }
.jc-bars i.js-back { background: var(--red); opacity: 0.35; }
.jc-bars i.js-skip { background: var(--paper-2); }
.jc-label { font-weight: 600; color: var(--ink); }
.tone-wait .jc-label { color: var(--orange); }
.tone-back .jc-label { color: var(--red); }
.tone-closed .jc-label { color: var(--ink-soft); font-weight: 500; }
.jc-wait { color: var(--ink-soft); font-size: 12.5px; }

/* ---------- Decision view ---------- */
.decision-card { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-lg); margin-bottom: 20px; overflow: hidden; }
.dc-left { padding: 22px 24px; display: flex; flex-direction: column; gap: 16px; border-right: 1px solid var(--rule); min-width: 0; }
.dc-right { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; background: color-mix(in srgb, var(--paper) 55%, var(--sheet)); min-width: 0; }
.dc-kicker { color: var(--orange); font-size: 13.5px; font-weight: 600; }
.decision-card h2 { font-size: 24px; margin: 4px 0 0; }
.dc-money { font-family: var(--font-display); font-size: 34px; font-weight: 700; line-height: 1; }
.dc-money small { font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--ink-soft); margin-left: 8px; }
.dc-kv { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 14.5px; }
.dc-kv dt { color: var(--ink-soft); }
.dc-kv dd { margin: 0; }
.dc-checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14.5px; }
.dc-checks li { display: flex; gap: 9px; align-items: flex-start; }
.dc-checks li .icon { margin-top: 3px; }
.dc-checks li.ok .icon { color: var(--green); }
.dc-checks li.warn .icon { color: var(--orange); }
.dc-checks li.pending { color: var(--ink-soft); }
.dc-thread { display: flex; flex-direction: column; gap: 12px; font-size: 14px; }
.dc-thread > div { border-left: 2px solid var(--rule-strong); padding-left: 12px; }
.dc-thread em { display: block; font-style: normal; color: var(--ink-soft); font-size: 12.5px; margin-bottom: 2px; }
.dc-thread .muted { color: var(--ink-soft); }
.dc-actions { margin-top: auto; padding-top: 6px; }
@media (max-width: 820px) {
  .decision-card { grid-template-columns: minmax(0, 1fr); }
  .dc-left { border-right: 0; border-bottom: 1px solid var(--rule); }
  .dc-actions button { flex: 1 1 auto; }
}

/* ---------- Today ---------- */
.today { max-width: 1280px; }
.today-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.today-head .subtitle { font-size: 16px; color: var(--ink); }
.today-lanes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; align-items: start; }
.lane { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.lane h2 { font-size: 17px; margin: 0; display: flex; align-items: baseline; gap: 10px; padding-bottom: 8px; border-bottom: 2px solid var(--ink); }
.lane-count { font-family: var(--font-display); font-size: 28px; font-weight: 700; line-height: 1; }
.lane.hot .lane-count { color: var(--orange); }
.lane.hot h2 { border-bottom-color: var(--orange-fill); }
.lane.theirs h2 { border-bottom-color: var(--rule-strong); color: var(--ink-soft); }
.tickets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ticket { display: flex; flex-direction: column; gap: 4px; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 14px; color: var(--ink); text-decoration: none; transition: border-color 0.15s ease; }
.ticket:hover { border-color: var(--ink-faint); text-decoration: none; color: var(--ink); }
.ticket:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.lane.theirs .ticket { background: transparent; }
.t-title { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.t-sub { color: var(--ink-soft); font-size: 13.5px; line-height: 1.4; }
.t-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.t-money { font-weight: 600; font-size: 14px; }
.t-money small { color: var(--ink-soft); font-weight: 500; }
.t-pill { display: inline-flex; align-items: center; gap: 8px; }
.lane-empty { color: var(--ink-soft); font-size: 14px; margin: 4px 0 0; padding: 14px 0; }
.lane-more { font-weight: 600; font-size: 14px; }
@media (max-width: 960px) { .today-lanes { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Contract page: steps and tabs ---------- */
#layout-nav:empty { display: none; }
.stepper { margin-bottom: 20px; }
.stepper ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stepper li > div, .stepper li > button { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; padding: 0; background: none; border: 0; border-radius: 0; color: inherit; font: inherit; align-items: stretch; }
.stepper li > button { cursor: pointer; }
.stepper li > button:hover b { text-decoration: underline; }
.stepper .step-bar { display: block; height: 5px; border-radius: 3px; background: var(--rule); margin-bottom: 8px; }
.stepper .step-done .step-bar { background: var(--red); }
.stepper .step-now .step-bar { background: var(--orange-fill); }
.stepper b { font-size: 14.5px; font-weight: 600; }
.stepper .step-now b { color: var(--orange); }
.stepper .step-todo b { color: var(--ink-soft); font-weight: 500; }
.stepper li span:last-child { font-size: 12.5px; color: var(--ink-soft); }
.step-nav { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule); }
.step-nav:has(#step-back):not(:has(#step-next)) { border-top: 0; padding-top: 0; }
.tabs { margin-bottom: 18px; }
.tab-seg > button { padding: 9px 18px; }
.review-card, .overview-card { margin-bottom: 20px; }
.review-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; align-items: start; margin-top: 14px; }
.review-grid > div { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.overview-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.overview-head h2 { margin: 0 0 6px; }
.next-step { display: flex; gap: 8px; align-items: flex-start; margin: 0; color: var(--ink); font-size: 15px; }
.next-step .icon { color: var(--orange); margin-top: 3px; }
.overview-facts { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--red); font-weight: 600; font-size: inherit; text-decoration: underline; cursor: pointer; display: inline; }
.action-bar { position: sticky; bottom: 0; background: var(--sheet); padding: 14px 0 10px; margin-bottom: -10px; border-top: 1px solid var(--rule); z-index: 5; }
@media (max-width: 760px) {
  .stepper ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Small layout helpers that replace inline styles */
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.field-head label { margin: 0; }
.field-head-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.stack-6 { display: flex; flex-direction: column; gap: 6px; }
.row-6 { display: flex; gap: 6px; align-items: center; }
.row-8 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.mt-6 { margin-top: 6px; }
.mb-20 { margin-bottom: 20px; }
.currency-code { width: 120px; text-transform: uppercase; }
.quick-stats-field { margin: 6px 0 12px; }
.form-section { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--rule); }
#contract-form > .form-section:first-of-type { margin-top: 26px; }
.section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.section-head h2, .section-head h3 { margin: 0; }
.section-head h3 { font-size: 17px; }
.section-head .subtitle { margin: 4px 0 0; }
.form-section-title { font-size: 16px; margin: 10px 0 0; padding-top: 14px; border-top: 1px solid var(--rule); grid-column: 1 / -1; }
.req { color: var(--danger); }
.scroll-hint { font-size: 12.5px; color: var(--ink-soft); margin: 0 0 6px; }
.upload-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 14px; flex-wrap: wrap; }
.upload-type { min-width: 200px; }
.upload-file { flex: 1; min-width: 240px; }
.ledger-table { min-width: 920px; }
.hint:empty { display: none; }

.card.actions-only { padding: 16px 24px; }
.card.actions-only #contract-form { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card.actions-only .step-nav, .card.actions-only .action-bar { margin: 0; padding: 0; border: 0; position: static; }
.card.actions-only #rejection-note:empty, .card.actions-only #form-alert:empty { display: none; }
.report-filters select { width: auto; max-width: 260px; }

/* ---------- Utility classes that replaced inline styles ---------- */
.nowrap { white-space: nowrap; }
.kv-label { color: var(--ink-soft); font-size: 12.5px; font-weight: 600; display: block; }
.text-meta { color: var(--ink-soft); font-size: 12.5px; }
.text-meta-size { font-size: 12.5px; }
.d-block { display: block; }
.text-strong { font-weight: 600; color: var(--ink); }
.text-ok { color: var(--green); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.va-middle { vertical-align: middle; }
.badge-neutral { background: var(--paper-2); color: var(--ink); }
.pad-14 { padding: 14px 16px; }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: 4px; }
.mb-6 { margin-bottom: 6px; }
.mb-8 { margin-bottom: 8px; }
.mb-10 { margin-bottom: 10px; }
.mb-12 { margin-bottom: 12px; }
.mb-14 { margin-bottom: 14px; }
.mb-16 { margin-bottom: 16px; }
.h-18 { font-size: 18px; }
.w-100 { width: 100%; }
.row-10 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack-8 { display: flex; flex-direction: column; gap: 8px; }
.btn-row-center { justify-content: center; gap: 12px; }
.input-toggle-wrap { position: relative; display: flex; align-items: center; }
.input-with-toggle { width: 100%; padding-right: 38px; }
.modal-center { text-align: center; max-width: 480px; padding: 28px 24px; }
.modal-title { margin-top: 0; font-size: 20px; color: var(--ink); }

/* ---------- Footer with the product name (moved out of the top bar) ---------- */
.app-footer { max-width: 1280px; margin: 40px auto 0; padding: 18px 24px 28px; border-top: 1px solid var(--rule);
  color: var(--ink-soft); font-size: 12.5px; text-align: center; }
@media (max-width: 640px) { .app-footer { margin-top: 28px; padding: 16px 16px 24px; } }
.topbar .brand-logo { height: 40px; }
@media (max-width: 640px) { .topbar .brand-logo { height: 32px; } }

/* ---------- Top bar: logo, links, then bell / name / log out; links fold into Menu below 1240px ---------- */
.topbar-row { display: flex; align-items: center; gap: 8px 16px; width: 100%; }
.topbar-row nav { margin-left: auto; }
.nav-end { display: flex; align-items: center; gap: 8px; }
.nav-menu-btn, .nav-mobile-only { display: none; }
.nav-menu-btn { align-items: center; gap: 6px; background: var(--sheet); color: var(--ink); border: 1px solid var(--rule);
  border-radius: var(--radius-sm); padding: 7px 12px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.nav-menu-btn:hover { background: var(--paper); }
.nav-menu-btn:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

@media (max-width: 1240px) {
  .topbar-row { flex-wrap: wrap; }
  .nav-end { margin-left: auto; }
  .nav-menu-btn { display: inline-flex; }
  .nav-desktop-only { display: none !important; }
  .topbar-row nav { display: none; order: 3; width: 100%; margin: 4px 0 2px; padding-top: 6px;
    border-top: 1px solid var(--rule); flex-direction: column; align-items: stretch; gap: 0; }
  .menu-open .topbar-row nav { display: flex; }
  .topbar-row nav > a { padding: 12px 6px; font-size: 15.5px; border-bottom: 1px solid var(--rule); border-radius: 0; }
  .topbar-row nav > a.active { box-shadow: inset 3px 0 0 var(--red); padding-left: 12px; }
  .topbar-row nav .nav-mobile-only { display: flex; }
  .nav-me { flex-direction: column; padding: 12px 6px 8px; color: var(--ink-soft); font-size: 13px; }
  .nav-me strong { color: var(--ink); font-size: 14.5px; }
  .topbar-row nav button[data-logout] { align-self: flex-start; margin: 4px 6px 8px; }
}

/* Checkboxes keep their size on phones (the 42px tap height above is for text inputs);
   the whole label stays the tap target */
input[type="checkbox"], input[type="radio"] { min-height: 0; width: 18px; height: 18px; flex: none; margin: 0; }
.checkbox-row { justify-content: flex-start; min-height: 42px; cursor: pointer; }

/* ---------- Client or vendor: its contracts, read live ---------- */
.pd-contracts { border-top: 1px solid var(--rule); padding-top: 16px; margin: 4px 0 16px; }
.pd-contracts h3 { font-size: 17px; margin: 0; }
.pc-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pc-count { font-family: var(--font-body, inherit); font-weight: 500; font-size: 13.5px; color: var(--ink-soft); margin-left: 6px; }
.pc-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-md, 10px); overflow: hidden; background: var(--sheet); }
.pc-list li + li { border-top: 1px solid var(--rule); }
.pc-row { display: grid; grid-template-columns: 130px minmax(0, 1fr) auto minmax(150px, auto); gap: 6px 18px; align-items: center;
  padding: 12px 16px; color: var(--ink); text-decoration: none; }
.pc-row:hover { background: var(--paper); text-decoration: none; }
.pc-row:focus-visible { outline: 2px solid var(--red); outline-offset: -2px; }
.pc-num { font-weight: 600; color: var(--red); white-space: nowrap; }
.pc-main { display: flex; flex-direction: column; min-width: 0; }
.pc-project { font-weight: 500; }
.pc-dates { color: var(--ink-soft); font-size: 13px; }
.pc-value { text-align: right; white-space: nowrap; }
.pc-value small { color: var(--ink-soft); }
@media (max-width: 720px) {
  .pc-row { grid-template-columns: 1fr auto; padding: 12px 14px; }
  .pc-main { grid-column: 1 / -1; order: 2; }
  .pc-stage { grid-column: 1 / -1; order: 3; }
  .pc-value { order: 1; }
}

/* ---------- Clients and vendors: clickable rows, contracts summary ---------- */
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--paper); }
.party-link { color: inherit; text-decoration: none; }
.party-link.party-name { font-weight: 700; }
.party-link:hover .text-strong, .party-link.party-name:hover { color: var(--red); text-decoration: underline; }
.party-link:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 2px; }
.pc-summary { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.pc-summary > div { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.pc-summary dt { color: var(--ink-soft); font-size: 13.5px; min-width: 190px; }
.pc-summary dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .pc-summary > div { flex-direction: column; gap: 0; }
  .pc-summary dt { min-width: 0; }
}

/* ---------- Contracts pager: "Per page" stays on one line ---------- */
.per-page { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; margin: 0; font-weight: 400; }
.per-page select { width: auto; min-width: 0; min-height: 0; font-size: 13px; padding: 3px 24px 3px 8px; }

/* ---------- Audit log: columns keep their room; the table scrolls sideways on narrow screens ---------- */
.table-scroll table.audit-table { min-width: 860px; table-layout: auto; }
.audit-table td { vertical-align: top; }
.audit-table td.audit-entity { min-width: 240px; max-width: 320px; }
.audit-table td.audit-actor { min-width: 170px; white-space: normal; }
.audit-table td.audit-details { min-width: 260px; }
.audit-table .entity-badge { display: inline-flex; flex-wrap: wrap; max-width: 100%; white-space: normal; }
.actor { display: flex; flex-direction: column; line-height: 1.3; }
.actor strong { font-weight: 600; }
.actor-role { color: var(--ink-soft); font-size: 12.5px; }
.audit-table td.audit-details { white-space: normal; overflow-wrap: anywhere; min-width: 220px; }
.audit-table td.audit-entity { white-space: normal; }
@media (max-width: 760px) {
  /* Phones: each entry becomes a card instead of a table row */
  .table-scroll table.audit-table { min-width: 0; }
  .audit-table thead { display: none; }
  .audit-table, .audit-table tbody, .audit-table tr, .audit-table td { display: block; width: auto; min-width: 0; max-width: none; }
  .audit-table tr { padding: 12px 0; border-bottom: 1px solid var(--rule); }
  .audit-table td { border: 0; padding: 2px 0; white-space: normal; }
  .audit-table td:first-child { display: inline-block; color: var(--ink-soft); font-size: 13px; margin-right: 8px; }
  .audit-table td:nth-child(2) { display: inline-block; }
  .audit-table td.audit-entity { margin-top: 6px; }
  .audit-table .actor { flex-direction: row; gap: 6px; align-items: baseline; flex-wrap: wrap; }
  .audit-table .actor::before { content: "By"; color: var(--ink-soft); font-size: 13px; }
}
.audit-table .entity-badge { max-width: 100%; }
.audit-table .entity-badge .entity-code { flex-shrink: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Settings: business sectors ---------- */
.sector-table td { vertical-align: top; }
.sector-table td .text-meta { white-space: normal; max-width: 520px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-3 { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); } }
#sector-form .span-3 { flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 10px; }

/* ---------- v1.0.1: version line, disabled password options, plain link button ---------- */
.signin-version { margin: 16px 0 0; text-align: center; color: var(--ink-soft); font-size: 12px; }
.checkbox-row.is-disabled { opacity: 0.55; cursor: not-allowed; }
.btn-link { background: none; border: 0; color: var(--ink-soft); font: inherit; font-size: 13.5px; padding: 8px; cursor: pointer; text-decoration: underline; }
.btn-link:hover { color: var(--red); }
