:root {
  --black: #0b0b0b;
  --ink: #1b1d1f;
  --muted: #6b7076;
  --line: #e3e5e8;
  --bg: #f6f7f8;
  --card: #fff;
  --green: #22b35e;
  --green-bg: #e3f6eb;
  --yellow: #f2c94c;
  --yellow-bg: #fff6d6;
  --red: #e5484d;
  --red-bg: #fde8e8;
  --accent: #6c5ce7;
  --radius: 10px;
  font-family: Montserrat, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  background: var(--black); color: #fff; padding: 0 24px; height: 64px; }
.brand { display: flex; flex-direction: column; text-decoration: none; line-height: 1; }
.wordmark { font-size: 24px; letter-spacing: 6px; font-weight: 500; }
.wordmark span { color: #fff; }
.brand small { font-size: 10px; letter-spacing: 4px; color: #9aa0a6; margin-top: 4px; text-transform: uppercase; }
nav { display: flex; gap: 4px; flex: 1; }
nav a { text-decoration: none; color: #b9bdc2; padding: 8px 12px; border-radius: 8px; font-weight: 500; }
nav a:hover { color: #fff; background: #1d1f22; }
nav a.active { color: #fff; background: #26292d; }
.user { display: flex; align-items: center; gap: 10px; color: #b9bdc2; font-size: 13px; }
.user b { color: #fff; font-weight: 600; }
.role-pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #26292d; color: #ddd; text-transform: uppercase; letter-spacing: 1px; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 22px; }

main { padding: 24px; max-width: 1600px; margin: 0 auto; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* page head */
.page-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; font-weight: 600; margin: 0; }
.page-head .total { color: var(--green); font-weight: 700; font-size: 18px; }
.page-head .spacer { flex: 1; }

.btn { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: #c9ccd0; }
.btn.primary { background: var(--black); color: #fff; border-color: var(--black); }
.btn.primary:hover { background: #2a2d31; }
.btn.green { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { color: var(--red); border-color: #f3c1c3; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-height: 38px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c8c2ff; border-color: var(--accent); }
.search { max-width: 280px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 700; }
.muted { color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { text-decoration: none; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 13px; }
.tabs a.active { background: var(--black); color: #fff; border-color: var(--black); }

/* summary chips */
.chips { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 140px; }
.chip b { display: block; font-size: 22px; }
.chip.red b { color: var(--red); } .chip.yellow b { color: #c99a00; } .chip.green b { color: var(--green); }

/* tables */
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 230px); }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th { position: sticky; top: 0; background: var(--black); color: #fff; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  text-align: left; padding: 10px; white-space: nowrap; z-index: 2; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: #fafafa; }
td.num { text-align: right; white-space: nowrap; }
.board td.ms { text-align: center; white-space: nowrap; padding: 0; min-width: 96px; border-left: 1px solid var(--line); }
.board td.ms button { all: unset; display: block; width: 100%; padding: 12px 6px; cursor: pointer; font-weight: 600; font-size: 13px; box-sizing: border-box; }
.board td.ms button:focus-visible { outline: 2px solid var(--accent); }
.ms-done { background: var(--green) !important; color: #fff; }
.ms-overdue { background: var(--red) !important; color: #fff; }
.ms-soon { background: var(--yellow) !important; color: #2b2300; }
.ms-later { color: var(--ink); }
.ms-empty { color: #c5c8cc; }
.board .sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; }
.board th.sticky-col { z-index: 3; background: var(--black); }
.prop a { font-weight: 700; text-decoration: none; }
.prop a:hover { text-decoration: underline; }
.sub { color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* deal timeline */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-row { display: grid; grid-template-columns: 22px 180px 170px 120px 1fr; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.tl-row.done { background: var(--green-bg); border-color: #bfe8cf; }
.tl-row.overdue { background: var(--red-bg); border-color: #f5c2c3; }
.tl-row.soon { background: var(--yellow-bg); border-color: #f3e2a4; }
.tl-row .lbl { font-weight: 700; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .5px; }
.badge.done { background: var(--green); color: #fff; } .badge.overdue { background: var(--red); color: #fff; }
.badge.soon { background: var(--yellow); color: #2b2300; } .badge.later { background: #eef0f2; color: var(--muted); }
.badge.status-active { background: #e8e5ff; color: #4b3fc7; } .badge.status-completed { background: var(--green-bg); color: #137a3f; } .badge.status-cancelled { background: #eee; color: #666; }
.notify { font-size: 12px; color: var(--muted); }
.party-row { display: grid; grid-template-columns: 170px 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.party-row .lbl { font-weight: 600; }
.multi { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { background: #eef0f2; border-radius: 99px; padding: 4px 6px 4px 10px; font-size: 12px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.tag button { all: unset; cursor: pointer; color: var(--muted); padding: 0 4px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 10px; border-top: 1px solid var(--line); z-index: 5; }

/* dialog */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,10,10,.45); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
dialog h3 { margin: 0; font-size: 17px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.error { color: var(--red); font-weight: 600; font-size: 13px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--black); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100; }
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

/* auth */
.auth { max-width: 420px; margin: 8vh auto; }
.auth .logo { background: var(--black); color: #fff; padding: 22px; border-radius: 14px 14px 0 0; text-align: center; }
.auth .logo .wordmark { font-size: 28px; }
.auth .card { border-radius: 0 0 14px 14px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }

code.link { display: block; background: #f1f2f4; padding: 10px; border-radius: 8px; word-break: break-all; font-size: 12px; }

@media (max-width: 1100px) {
  nav { display: none; position: absolute; top: 64px; left: 0; right: 0; background: var(--black); flex-direction: column; padding: 8px; }
  nav.open { display: flex; }
  .menu-toggle { display: block; margin-left: auto; }
  .user { display: none; }
  .grid.c3, .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tl-row { grid-template-columns: 22px 1fr 150px; }
  .tl-row .notify, .tl-row .badge-cell { grid-column: 2 / -1; }
}
@media (max-width: 640px) {
  main { padding: 14px 16px; }
  .topbar { padding: 0 16px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .party-row { grid-template-columns: 1fr; }
  .search { max-width: none; }
}

/* polish after first screenshots */
.user .btn { background: transparent; color: #e6e7e9; border-color: #3a3d42; }
.user .btn:hover { border-color: #6b7076; }
label.field input, label.field select, label.field textarea { font-size: 14px; font-weight: 400; color: var(--ink); }
.board td.prop { min-width: 210px; }
.board td { white-space: nowrap; }
.board td.prop, .board td:nth-child(3) { white-space: normal; }
.board td.ms button { padding: 10px 6px; }
.board td.ms { min-width: 72px; }
a.btn { text-decoration: none; display: inline-block; }
.legend { flex-wrap: wrap; }

/* ---------- v2: separate sign-ins + friendly admin ---------- */
.auth .sub { color: #9aa0a6; letter-spacing: 3px; margin-top: 8px; font-size: 11px; }
.auth.office .logo { background: linear-gradient(135deg, #000, #23262b); border-bottom: 3px solid var(--green); }
.auth .card { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.auth .switch { margin: 4px 0 0; text-align: center; font-size: 13px; }
.btn.big { padding: 12px 18px; font-size: 15px; }
a.chip { text-decoration: none; color: inherit; transition: border-color .15s; }
a.chip:hover { border-color: #b9bdc2; }
.card.alert { background: var(--red-bg); border-color: #f5c2c3; font-weight: 600; }
.progress { height: 8px; background: #eef0f2; border-radius: 99px; overflow: hidden; margin: -4px 0 14px; }
.progress i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.step { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; }
.step > div { flex: 1; }
.step .num { width: 30px; height: 30px; border-radius: 50%; background: var(--black); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.step.done { background: #fafbfa; } .step.done .num { background: var(--green); } .step.done b { color: var(--muted); text-decoration: line-through; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile { display: flex; flex-direction: column; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; text-decoration: none; transition: transform .1s, box-shadow .15s; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.07); }
.tile .ico { font-size: 26px; } .tile b { font-size: 16px; } .tile .muted { font-size: 13px; }
.group-title { font-size: 15px; margin: 20px 0 10px; }
.people { display: flex; flex-direction: column; gap: 8px; }
.person { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.person.inactive { opacity: .55; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: #6b7076; flex: none; }
.avatar.admin { background: var(--black); } .avatar.manager { background: var(--accent); } .avatar.agent { background: #2f80ed; }
.pinfo { flex: 1; min-width: 0; } .pinfo .muted { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.pmeta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.pactions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.role-pick { display: flex; flex-direction: column; gap: 8px; }
.role-opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.role-opt:has(input:checked) { border-color: var(--black); background: #f6f7f8; }
.role-opt span { display: flex; flex-direction: column; } .role-opt small { color: var(--muted); font-size: 12px; }
.creds { background: #f6f7f8; border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.creds div { display: flex; flex-direction: column; } .creds .muted { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 18px; letter-spacing: 1px; }
.ok { color: #137a3f; font-weight: 600; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row span { display: flex; flex-direction: column; gap: 2px; }
input.switch { appearance: none; width: 46px; height: 26px; border-radius: 99px; background: #d5d8dc; position: relative; cursor: pointer; flex: none; transition: background .15s; }
input.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
input.switch:checked { background: var(--green); } input.switch:checked::after { left: 23px; }
.field-block { padding: 14px 0 4px; display: flex; flex-direction: column; gap: 8px; }
.day-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.day-chip input { position: absolute; opacity: 0; pointer-events: none; }
.day-chip span { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; font-weight: 600; font-size: 13px; background: #fff; }
.day-chip input:checked + span { background: var(--black); color: #fff; border-color: var(--black); }
.day-chip input:focus-visible + span { outline: 2px solid var(--accent); }
.status-line { margin-top: 14px; padding: 10px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; }
.status-line.ok { background: var(--green-bg); } .status-line.warn { background: var(--yellow-bg); color: #6b5300; }
.save-bar { display: flex; align-items: center; gap: 12px; margin: -4px 0 18px; }
.activity { display: flex; flex-direction: column; max-height: 420px; overflow: auto; }
.act { display: flex; gap: 14px; padding: 8px 0; border-bottom: 1px solid #f0f1f2; font-size: 13px; }
.act .when { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 92px; }
@media (max-width: 640px) {
  .person { flex-wrap: wrap; } .pactions { width: 100%; justify-content: flex-start; }
  .step { flex-wrap: wrap; }
}
.warn-box { background: var(--yellow-bg); color: #6b5300; padding: 10px 12px; border-radius: 8px; margin: 0; font-weight: 600; font-size: 13px; }
@media (min-width: 1100px) { .tiles { grid-template-columns: repeat(3, 1fr); } }

/* ---------- v3: approvals + messages ---------- */
.nbadge { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px; border-radius: 99px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.banner { border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; border: 1px solid var(--line); background: #fff; }
.banner.yellow { background: var(--yellow-bg); border-color: #f3e2a4; }
.banner.red { background: var(--red-bg); border-color: #f5c2c3; }
.banner.info { background: #eef4ff; border-color: #cfdcf7; color: #23406e; font-size: 13px; }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
table.diff { margin-top: 10px; background: #fff; border-radius: 8px; overflow: hidden; font-size: 13px; }
table.diff th { position: static; background: #f1f2f4; color: var(--muted); }
table.diff tr.hl td { background: #fff6d6; }
.card.alert-y { display: block; background: var(--yellow-bg); border-color: #f3e2a4; text-decoration: none; }
.approval .ahead { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 6px; }
.approval .banner-actions { margin-top: 0; }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow: auto; margin-bottom: 12px; }
.thread.inbox { max-height: none; margin: 0; }
.msg { background: #f6f7f8; border-radius: 10px; padding: 10px 12px; max-width: 80%; }
.msg.mine { background: #eef4ff; align-self: flex-end; }
.thread.inbox .msg { max-width: none; }
.mhead { display: flex; gap: 8px; align-items: center; font-size: 13px; flex-wrap: wrap; }
.mhead .muted:last-of-type { margin-left: auto; }
.mbody { white-space: pre-wrap; margin-top: 4px; color: var(--ink); line-height: 1.45; }
.compose { display: flex; gap: 8px; align-items: flex-end; }
.compose textarea { min-height: 60px; }

/* ---------- v4: commission (admin) + TV address ---------- */
.page-head .total.comm { color: #6c5ce7; }
.comm-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; position: relative; padding: 8px; margin: -8px; border-radius: 10px; background: #f4f2ff; }
.comm-pair .admin-only { position: absolute; top: -9px; right: 8px; font-size: 10px; font-weight: 700; color: #6c5ce7; background: #fff; border: 1px solid #ddd6fe; border-radius: 99px; padding: 1px 8px; }
.grid.c4 .comm-pair { grid-column: span 1; }
.tv-addr { display: flex; flex-direction: column; gap: 4px; background: #0b0b0b; color: #fff; border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.tv-addr .muted { color: #9aa0a6; font-size: 12px; } .tv-addr b { font-size: 20px; letter-spacing: .5px; word-break: break-all; }
.tv-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tv-input span { padding: 0 10px; color: var(--muted); font-size: 13px; white-space: nowrap; background: #f6f7f8; align-self: stretch; display: flex; align-items: center; }
.tv-input input { border: 0 !important; border-radius: 0 !important; }
/* sign-in page: clear link between the agent and admin sign-in pages */
.auth .switch-box { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--line); text-align: center; font-size: 13px; }
.auth .switch-btn { display: block; text-align: center; padding: 11px 14px; font-size: 14px; }
