:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --text: #1f2d36;
  --muted: #74838c;
  --line: #dfe7eb;
  --blue: #2f80ed;
  --green: #22a668;
  --green-dark: #168451;
  --orange: #f59e0b;
  font-family: "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
.shell { width: min(1180px, 100%); margin: 0 auto; padding: 22px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0; font-size: 16px; }
p { margin: 5px 0 0; }
.muted, .panel-head p, .schedule-head p { color: var(--muted); font-size: 13px; }
.badge, .soft-badge { padding: 7px 11px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.badge { background: #fff3d8; color: #9a6510; }
.badge.ready { background: #dcf7e9; color: #137747; }
.soft-badge { background: #edf3f6; color: #5e707a; }
.soft-badge.ready { background: #dcf7e9; color: #137747; }
.notice { margin: 0 0 16px; padding: 12px 14px; border: 1px solid #f2c96d; border-radius: 10px; background: #fff8e8; color: #7d5710; }
.notice.error { border-color: #ef9a9a; background: #fff0f0; color: #a42424; }
.notice.success { border-color: #8bd0ab; background: #effbf4; color: #11683d; }
.summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary article { min-height: 82px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.summary span { display: block; color: var(--muted); font-size: 12px; }
.summary strong { display: block; margin-top: 8px; font-size: 20px; }
.summary small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.summary-start { border-left: 3px solid var(--orange) !important; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { border: 0; border-radius: 9px; padding: 10px 15px; background: transparent; color: #5c6c75; cursor: pointer; font-weight: 700; }
.tab.active { background: #e3f0ff; color: #1767c2; }
.panel { display: none; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); padding: 20px; box-shadow: 0 2px 10px rgb(31 45 54 / 4%); }
.panel.active { display: block; }
.panel-head, .schedule-head, .form-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.panel-head { margin-bottom: 20px; }
.template-manager { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: -4px 0 20px; padding: 15px; border: 1px solid #cfdde5; border-radius: 11px; background: #f8fbfc; }
.template-copy { display: flex; align-items: center; gap: 12px; min-width: 0; }
.template-copy h3 { margin-bottom: 3px; }
.template-copy p { color: #536872; font-size: 12px; }
.template-copy small { display: block; margin-top: 5px; color: #87969e; font-size: 10px; }
.template-icon { flex: 0 0 auto; padding: 10px 8px; border: 1px solid #9bb9ca; border-radius: 7px; background: #fff; color: #315d74; font-size: 10px; font-weight: 900; letter-spacing: .06em; }
.template-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.template-upload { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 0 13px; border-radius: 8px; background: #315d74; color: #fff; cursor: pointer; font-size: 12px; font-weight: 800; white-space: nowrap; }
.template-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.template-upload.disabled { cursor: wait; opacity: .65; }
.template-reset { border: 0; background: transparent; color: #9a4c42; cursor: pointer; font-size: 11px; text-decoration: underline; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 6px; color: #53636c; font-size: 12px; font-weight: 700; }
input, select { width: 100%; height: 40px; padding: 0 11px; border: 1px solid #cad6dc; border-radius: 8px; background: #fff; color: var(--text); outline: 0; }
textarea { width: 100%; min-height: 92px; padding: 10px 11px; resize: vertical; border: 1px solid #cad6dc; border-radius: 8px; background: #fff; color: var(--text); outline: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgb(47 128 237 / 12%); }
input:disabled { background: #eef2f4; color: #9aa6ac; }
.crm-sync { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: -4px 0 20px; padding: 13px 15px; border: 1px solid #b8d6f8; border-radius: 10px; background: #f1f7ff; }
.crm-sync > div { display: flex; align-items: center; gap: 11px; min-width: 0; }
.crm-sync-mark { display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 34px; border-radius: 8px; background: #2f80ed; color: #fff; font-size: 11px; font-weight: 900; letter-spacing: .05em; }
.crm-sync h3 { font-size: 14px; }
.crm-sync p { color: #647985; font-size: 11px; }
.cooperation-card { margin: 18px 0 20px; padding: 16px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfd; }
.cooperation-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.cooperation-head p { color: var(--muted); font-size: 12px; }
.cooperation-grid small { color: #8b999f; font-size: 10px; font-weight: 500; }
.cooperation-card .mortgage-row { margin: 14px 0 0; border: 1px solid #e4eaed; background: #fff; }
.mortgage-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 18px 0; padding: 15px; border-radius: 10px; background: #f7f9fa; }
.mortgage-row p { max-width: 430px; color: var(--muted); font-size: 12px; text-align: right; }
.start-rule { display: flex; align-items: center; gap: 13px; margin: 18px 0 0; padding: 14px 15px; border: 1px solid #b8d6f8; border-radius: 10px; background: #f1f7ff; }
.start-rule-mark { flex: 0 0 auto; padding: 8px 10px; border-radius: 8px; background: var(--blue); color: #fff; font-size: 18px; font-weight: 900; }
.start-rule strong { font-size: 14px; }
.start-rule p { color: #5f7180; font-size: 12px; }
.switch-label { display: flex; align-items: center; gap: 9px; min-height: 40px; font-size: 14px; color: var(--text); }
.switch-label input { width: 18px; height: 18px; }
.pricing-editor { margin: 20px 0 24px; }
.pricing-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.pricing-heading p { color: var(--muted); font-size: 12px; }
.pricing-grand { flex: 0 0 auto; text-align: right; }
.pricing-grand span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.pricing-grand strong { display: block; margin-top: 3px; color: #173f52; font-size: 21px; }
.service-pricing { display: grid; gap: 12px; }
.service-group { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.service-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 13px; background: #f2f6f8; cursor: pointer; list-style: none; user-select: none; }
.service-group-head::-webkit-details-marker { display: none; }
.service-group-head:hover { background: #eaf1f4; }
.service-group-head:focus-visible { outline: 3px solid rgb(47 128 237 / 20%); outline-offset: -3px; }
.service-group[open] .service-group-head { border-bottom: 1px solid var(--line); }
.service-group-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.service-chevron { width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 6px solid #6c7f89; transition: transform .18s ease; }
.service-group[open] .service-chevron { transform: rotate(90deg); }
.service-group-head h4 { margin: 0; color: #3e535e; font-size: 12px; text-transform: uppercase; letter-spacing: .035em; }
.service-group-head strong { font-size: 13px; }
.service-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 160px; align-items: center; gap: 12px; min-height: 62px; padding: 10px 13px; border-top: 1px solid #edf1f3; }
.service-group-head + .service-row { border-top: 0; }
.service-number { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #edf3f6; color: #667983; font-size: 11px; font-weight: 900; }
.service-copy strong { display: block; color: #344851; font-size: 12px; line-height: 1.4; }
.service-copy small { display: block; margin-top: 4px; color: #8a989f; font-size: 10px; }
.service-price { position: relative; }
.service-price input { padding-right: 30px; text-align: right; font-weight: 800; }
.service-price span { position: absolute; top: 50%; right: 11px; transform: translateY(-50%); color: #85939a; font-size: 12px; pointer-events: none; }
.service-row.mortgage-disabled { background: #fafafa; }
.service-row.mortgage-disabled .service-copy { opacity: .55; }
.schedule-head { margin: 18px 0 10px; }
.schedule { display: grid; gap: 8px; }
.schedule-row { display: grid; grid-template-columns: 42px 1fr 1fr; align-items: center; gap: 10px; }
.schedule-row b { text-align: center; color: #87959d; }
.primary, .secondary, .paid-button, .download { border: 0; border-radius: 8px; cursor: pointer; font-weight: 800; }
.primary { min-height: 42px; padding: 0 18px; background: var(--blue); color: #fff; }
.secondary { min-height: 36px; padding: 0 13px; background: #eaf1f5; color: #435761; }
.form-footer { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
button:disabled { cursor: wait; opacity: .65; }
.payment-dashboard { margin-bottom: 20px; }
.payment-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.payment-metrics article { min-height: 94px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafb; }
.payment-metrics span, .payment-metrics small { display: block; color: var(--muted); font-size: 11px; }
.payment-metrics strong { display: block; margin: 8px 0 4px; font-size: 18px; }
.start-progress { margin: 14px 0 22px; padding: 14px; border: 1px solid #c9dce8; border-radius: 10px; background: #f7fbfd; }
.progress-copy { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; font-size: 12px; }
.progress-copy span { color: #5b6e78; font-weight: 700; }
.progress-track { height: 12px; overflow: hidden; border-radius: 999px; background: #dce6eb; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .25s ease; }
.ledger-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.ledger-head p { color: var(--muted); font-size: 12px; }
.payment-ledger { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.ledger-table { min-width: 730px; }
.ledger-row { display: grid; grid-template-columns: 46px 1fr 1fr 1fr 1fr 1.1fr; align-items: center; min-height: 48px; border-top: 1px solid var(--line); font-size: 13px; }
.ledger-row:first-child { border-top: 0; }
.ledger-row > * { padding: 10px 12px; }
.ledger-header { min-height: 38px; background: #f2f6f8; color: #677984; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.payment-status { display: inline-block; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-style: normal; font-weight: 800; white-space: nowrap; }
.payment-status.paid { background: #dcf7e9; color: #137747; }
.payment-status.partial { background: #e7f1ff; color: #1767c2; }
.payment-status.overdue { background: #ffe6e6; color: #a42424; }
.payment-status.upcoming { background: #edf2f5; color: #5c6c75; }
.payment-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding-top: 20px; border-top: 1px solid var(--line); }
.paid-button { min-height: 54px; background: var(--green); color: #fff; font-size: 17px; }
.paid-button:hover { background: var(--green-dark); }
.history { display: grid; gap: 10px; }
.history-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 15px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; }
.history-item h4 { margin: 0; font-size: 14px; }
.history-item p { color: var(--muted); font-size: 12px; }
.history-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.danger-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid #efb4b4; border-radius: 8px; background: #fff4f4; color: #bd3535; cursor: pointer; transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease; }
.danger-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.danger-icon:hover { border-color: #c63d3d; background: #c63d3d; color: #fff; transform: translateY(-1px); }
.danger-icon:focus-visible { outline: 3px solid rgb(198 61 61 / 20%); outline-offset: 2px; }
.download { padding: 8px 11px; background: #e6f1ff; color: #1767c2; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.agent-mode .summary { display: none; }
.agent-mode .tabs .tab:not([data-tab="referrals"]) { display: none; }
.agent-mode .tabs { margin-top: 4px; }
.access-denied .summary,
.access-denied .tabs,
.access-denied .tab-panel { display: none; }
.badge.denied { background: #ffe8e8; color: #b42318; }
.referral-workspace { padding: 0; overflow: hidden; }
.agent-hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 24px; border-bottom: 1px solid #d8e4e9; background: linear-gradient(115deg, #eff8ff 0%, #f8fbfc 62%, #eef8f2 100%); }
.agent-hero h2 { margin-top: 2px; font-size: 24px; }
.agent-hero > div > p:last-child { max-width: 660px; color: #60747e; font-size: 13px; }
.agent-deal-link { flex: 0 0 auto; padding: 9px 12px; border: 1px solid #b7cfdb; border-radius: 8px; background: rgb(255 255 255 / 72%); color: #265b73; font-size: 12px; font-weight: 800; text-decoration: none; }
.agent-deal-link:hover { border-color: #6e9db3; background: #fff; }
.agent-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.agent-metrics article { min-height: 90px; padding: 17px 20px; border-left: 1px solid var(--line); background: #fff; }
.agent-metrics article:first-child { border-left: 0; }
.agent-metrics span { display: block; color: var(--muted); font-size: 11px; }
.agent-metrics strong { display: block; margin-top: 8px; color: #203944; font-size: 22px; }
.referral-layout { display: grid; grid-template-columns: minmax(280px, 350px) minmax(0, 1fr); min-height: 470px; }
.referral-form { display: grid; align-content: start; gap: 15px; padding: 22px; border-right: 1px solid var(--line); background: #f8fafb; }
.referral-form-head { margin-bottom: 3px; }
.referral-form-head > span { display: inline-block; margin-bottom: 7px; padding: 4px 7px; border-radius: 5px; background: #dcecff; color: #1767c2; font-size: 10px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.referral-form-head p { color: var(--muted); font-size: 12px; }
.referral-submit { width: 100%; margin-top: 3px; }
.referral-register { min-width: 0; padding: 22px; }
.referral-register-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.referral-list { display: grid; gap: 9px; }
.referral-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 18px; min-height: 80px; padding: 13px 14px; border: 1px solid var(--line); border-left: 3px solid #8cb9d0; border-radius: 9px; background: #fff; }
.referral-card-main { min-width: 0; }
.referral-card-main h4 { overflow: hidden; margin: 0; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.referral-card-main p { color: var(--muted); font-size: 11px; }
.referral-card-side { display: grid; justify-items: end; gap: 7px; }
.referral-stage { display: inline-block; max-width: 220px; overflow: hidden; padding: 5px 8px; border-radius: 999px; background: #edf3f6; color: #536872; font-size: 10px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.referral-stage.won { background: #dcf7e9; color: #137747; }
.referral-stage.lost { background: #ffe8e8; color: #a42424; }
.referral-card-link { color: #1767c2; font-size: 11px; font-weight: 800; text-decoration: none; }
.referral-card-link:hover { text-decoration: underline; }
@media (max-width: 760px) {
  .shell { padding: 14px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .payment-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.three, .payment-form { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .template-manager, .crm-sync, .mortgage-row, .pricing-heading { align-items: stretch; flex-direction: column; }
  .template-actions { justify-content: flex-start; }
  .mortgage-row p { text-align: left; }
  .pricing-grand { text-align: left; }
  .service-row { grid-template-columns: 34px minmax(0, 1fr); }
  .service-price { grid-column: 2; }
  .topbar { align-items: center; }
  .agent-hero { align-items: stretch; flex-direction: column; }
  .agent-deal-link { align-self: flex-start; }
  .agent-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .agent-metrics article:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .agent-metrics article:nth-child(4) { border-top: 1px solid var(--line); }
  .referral-layout { grid-template-columns: 1fr; }
  .referral-form { border-right: 0; border-bottom: 1px solid var(--line); }
  .referral-card { grid-template-columns: 1fr; }
  .referral-card-side { justify-items: start; }
}
