:root {
  --bg: #f4f7f6; --surface: #ffffff; --surface-2: #f0f5f3; --text: #1f2d2a; --muted: #5f706c;
  --border: #dae4e0; --primary: #0f7c6e; --primary-dark: #0b6559; --primary-soft: rgba(15, 124, 110, .12);
  --danger: #c62828; --danger-soft: rgba(198, 40, 40, .1); --warn-soft: #fff6d6; --field: #fcfdfd;
  --shadow: 0 8px 28px rgba(20, 60, 50, .08); --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514; --surface: #172120; --surface-2: #1d2a28; --text: #e3ece9; --muted: #9bb0ab;
    --border: #2b3a37; --primary: #2bb3a0; --primary-dark: #229584; --primary-soft: rgba(43, 179, 160, .18);
    --danger: #ff6f61; --danger-soft: rgba(255, 111, 97, .14); --warn-soft: #3a3418; --field: #121b1a;
    --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }

/* auth pages */
.auth-card { width: 100%; max-width: 500px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; }
.auth-card h1 { color: var(--primary); text-align: center; margin-bottom: 4px; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth-links { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; text-align: center; }

/* forms */
.field { margin-bottom: 14px; position: relative; }
.field > label, .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.input, .select, .textarea { width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--field); border: 1px solid var(--border); border-radius: 8px; outline: none; transition: border-color .15s, box-shadow .15s; }
.textarea { min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ltr { direction: ltr; text-align: left; }
.has-error .input, .has-error .select, .has-error .textarea { border-color: var(--danger); }
.has-error.boxed { outline: 2px solid var(--danger); outline-offset: 2px; border-radius: 8px; }
.error { color: var(--danger); font-size: 13px; font-weight: 600; margin-top: 6px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
.warn { background: var(--warn-soft); color: var(--danger); font-size: 13px; font-weight: 600; padding: 8px 10px; border-radius: 8px; margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
@media (max-width: 520px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; padding: 6px; cursor: pointer; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; }
legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-left: 70px; }
.pw-toggle { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; padding: 6px; }
/* hidden for people (bot trap / copy helper) without widening the page: important on RTL phone screens */
.hp { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; opacity: 0; pointer-events: none; }
.section-title { font-weight: 700; color: var(--primary); margin: 18px 0 10px; font-size: 15px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; min-height: 46px; font-size: 16px; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 4px 6px; min-height: auto; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .input:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
.spinner { width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
.spinner.dark { border-color: var(--primary); border-top-color: transparent; width: 28px; height: 28px; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 12px 0 0; }

/* app shell */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: 0 16px; min-height: 58px; }
.brand { font-weight: 800; color: var(--primary); text-decoration: none; font-size: 17px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 600; }
.nav a.active, .nav a:hover { color: var(--primary); background: var(--primary-soft); }
.user-menu { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.menu-btn { display: none; }
@media (max-width: 760px) {
  .menu-btn { display: inline-flex; margin-inline-start: auto; }
  .nav, .user-menu { display: none; }
  .topbar.open .topbar-inner { flex-wrap: wrap; padding-bottom: 10px; }
  .topbar.open .nav { display: flex; flex-direction: column; width: 100%; order: 3; }
  .topbar.open .user-menu { display: flex; width: 100%; order: 4; justify-content: space-between; }
}
.page { max-width: 1200px; margin: 0 auto; padding: 22px 16px 60px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 20px; }
.form-card { max-width: 760px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.tile { display: block; text-decoration: none; color: var(--text); }
.tile .num { font-size: 32px; font-weight: 800; color: var(--primary); }
.tile:hover { border-color: var(--primary); }

/* tables */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .input { max-width: 340px; flex: 1; min-width: 180px; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); font-size: 13px; color: var(--muted); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.check-col, th.check-col { width: 40px; }
td.check-col input, th.check-col input { width: 18px; height: 18px; accent-color: var(--primary); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.count { color: var(--muted); font-size: 14px; }
@media (max-width: 760px) {
  /* card layout for the system's own lists only — never for contract documents */
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr { border-bottom: 1px solid var(--border); padding: 8px 4px; position: relative; }
  .table-wrap td { border: 0; padding: 4px 12px; }
  .table-wrap td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
  .table-wrap td.check-col { position: absolute; left: 6px; top: 10px; width: auto; }
}

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 20, 18, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; max-width: 640px; width: 100%; max-height: 85vh; overflow: auto; padding: 20px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1f2d2a; color: #fff;
  padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* stage 2: contracts */
.nav { flex-wrap: wrap; }
.home-sub { margin: 26px 0 12px; font-size: 16px; color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { text-decoration: none; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.issue-section { padding: 6px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.issue-section:last-of-type { border-bottom: 0; }
.fee-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.fee-fields { display: flex; gap: 8px; align-items: center; }
.fee-input { width: 110px; }
.fee-unit { width: 150px; }
.picker .input { margin-bottom: 6px; }
.pick-list { max-height: 230px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--field); }
.pick-item { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 14.5px; }
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover { background: var(--surface-2); }
.pick-item.on { background: var(--primary-soft); font-weight: 600; }
.pick-item input { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
.pick-empty { padding: 14px; text-align: center; }
.quick-add { border: 1px dashed var(--primary); border-radius: 10px; padding: 12px; margin-top: 8px; }
.radios { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.bundle { margin-bottom: 14px; }
.doc-list { margin: 0 0 12px; padding-inline-start: 20px; color: var(--muted); }
.share { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.viewed { background: #fff1cc; color: #8a5a00; }
.badge.signed { background: #d9f3e6; color: #0c6b45; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.template-body { min-height: 420px; font-size: 15px; line-height: 1.7; }
.vars { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; margin-bottom: 14px; }
.var { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: right; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.var:hover { border-color: var(--primary); }
.var code { direction: ltr; color: var(--primary); font-weight: 700; }
.confirm-modal { max-width: 420px; }
.confirm-text { font-size: 16px; margin: 4px 0 16px; }
@media (max-width: 760px) {
  .topbar.open .nav { flex: 0 0 100%; gap: 2px; padding-top: 6px; border-top: 1px solid var(--border); }
  .topbar.open .nav a { padding: 12px 10px; }
  .topbar.open .user-menu { flex: 0 0 100%; padding-top: 8px; border-top: 1px solid var(--border); }
}

/* stage 3: messaging */
.bell { position: relative; text-decoration: none; font-size: 19px; padding: 6px 8px; border-radius: 8px; }
.bell:hover, .bell.active { background: var(--primary-soft); }
.bell-count { position: absolute; top: 0; left: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
@media (max-width: 760px) { .bell { margin-inline-start: auto; } .menu-btn { margin-inline-start: 0; } }
.send-panel { background: var(--surface-2); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.send-row { display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; }
.send-history { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.share-label { margin-top: 4px; color: var(--muted); font-size: 13px; }
.badge.queued { background: #e6eefc; color: #2a4fa0; }
.badge.sent, .badge.simulated { background: #d9f3e6; color: #0c6b45; }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.notif-list { padding: 0; overflow: hidden; }
.notif { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.notif:last-child { border-bottom: 0; }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--primary-soft); }
.notif-icon { font-size: 20px; }
.notif-main { flex: 1; display: flex; flex-direction: column; }
.preview { display: inline-block; max-width: 340px; font-size: 13px; color: var(--muted); }
.admin-form { margin-top: 18px; }
.test-row { display: flex; gap: 8px; flex-wrap: wrap; }
.test-row .input { max-width: 280px; }
.table-wrap td .ltr { white-space: nowrap; }

/* audit fixes */
.fee-vat { width: 150px; }
@media (max-width: 520px) { .fee-fields { flex-wrap: wrap; } .fee-input, .fee-unit, .fee-vat { width: calc(50% - 4px); } }
.link-box { background: var(--primary-soft); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.link-row { display: flex; gap: 8px; flex-wrap: wrap; }
.link-field { flex: 1; min-width: 200px; font-size: 14px; background: var(--surface); }
.btn.wa { background: #25d366; border-color: #25d366; color: #073b1c; }
.btn.wa:hover { background: #1ebe5a; }
.btn.wa.big { display: block; width: 100%; text-align: center; font-size: 18px; padding: 14px 16px; font-weight: 700; }
.wa-box { margin-bottom: 12px; }
.wa-box .hint { margin-top: 6px; }
.send-modes { border: 0; padding: 0; margin: 12px 0 4px; display: flex; gap: 16px; flex-wrap: wrap; }
.send-modes legend { margin-bottom: 6px; }
.badge.sent { background: #e6eefc; color: #2a4fa0; }
.badge.cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.summary-head { margin-bottom: 14px; }
.preview-doc { margin-bottom: 14px; }
.client-history { margin-top: 18px; }
.client-history .table-wrap { margin-bottom: 12px; }
.preview-doc { background: #fff; color: #111; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.preview-doc .contract { padding: 22px 18px; }

/* picker editing + exclusivity */
.pick-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.pick-row:last-child { border-bottom: 0; }
.pick-row .pick-item { flex: 1; border-bottom: 0; }
.pick-edit { background: none; border: 0; color: var(--primary); font: inherit; font-size: 13px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.pick-edit:hover { text-decoration: underline; }
.ex-summary { font-weight: 700; color: var(--primary); margin: 4px 0 8px; }
.warn-text { color: #8a5a00; font-weight: 600; font-size: 13px; }
.ok-text { color: #0c6b45; font-weight: 700; }
.bundle-head { margin-bottom: 8px; }
table.mini { width: 100%; border-collapse: collapse; }
table.mini td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
@media (prefers-color-scheme: dark) { .warn-text { color: #f0c36b; } .ok-text { color: #6fd6a6; } }
