:root {
  --ink: #17212b;
  --muted: #66717d;
  --line: #d8dee5;
  --soft: #f4f7f8;
  --panel: #ffffff;
  --teal: #127c89;
  --teal-dark: #0a5660;
  --lime: #c7df4d;
  --amber: #b56b18;
  --red: #b83838;
  --shadow: 0 18px 60px rgba(23, 33, 43, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef3f4;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #111c24;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.login-card img {
  width: 174px;
  height: auto;
}

.login-card h1 {
  margin: 0;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.app-locked {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111c24;
  color: #f8fbfb;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: grid;
  gap: 12px;
}

.brand img {
  width: 168px;
  height: auto;
  display: block;
}

.brand span {
  font-weight: 700;
  letter-spacing: 0;
}

.context-panel {
  display: grid;
  gap: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

label {
  display: grid;
  gap: 7px;
  color: inherit;
  font-weight: 650;
  font-size: 0.86rem;
}

.context-panel label {
  color: #cbd8dd;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  background: transparent;
  color: #dce7ea;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  background: #e9f8fa;
  color: #10222c;
}

.workspace {
  padding: 30px;
  display: grid;
  gap: 22px;
  align-content: start;
}

.topbar,
.section-heading,
.topbar-actions,
.filters,
.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
}

.topbar,
.section-heading {
  justify-content: space-between;
  gap: 16px;
}

.modal-head {
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.modal-head .icon-button {
  flex: 0 0 38px;
  margin-left: auto;
}

.topbar h1,
.section-heading h2,
.modal-head h2,
.audit-panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.filters,
.modal-actions {
  gap: 10px;
}

.primary,
.ghost,
.google-login,
.icon-button {
  border-radius: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary {
  background: var(--teal);
  color: #fff;
  padding: 0 16px;
}

.primary.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.ghost.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.danger.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.primary:hover {
  background: var(--teal-dark);
}

.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  padding: 0 14px;
}

.google-login {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  padding: 0 14px;
}

.google-login:hover,
.ghost:hover {
  border-color: #b6c3cb;
  background: #f8fbfb;
}

.google-login span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #1a73e8;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 900;
}

.icon-button {
  width: 38px;
  background: #f1f5f6;
  color: var(--ink);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metrics article,
.audit-panel,
.lead-card,
.broker-card,
.audit-entry,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(23, 33, 43, 0.02);
}

.metrics article {
  padding: 18px;
}

.metrics span,
.lead-meta,
td,
.scope-badge,
.audit-entry time {
  color: var(--muted);
}

.metrics strong {
  display: block;
  margin-top: 7px;
  font-size: clamp(1.35rem, 2.5vw, 2rem);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.lead-list,
.broker-grid,
.audit-log,
.target-list,
.product-grid,
.summary-grid,
.access-grid {
  display: grid;
  gap: 12px;
}

.product-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.product-grid > .empty-state {
  grid-column: 1 / -1;
}

.product-card {
  min-height: 220px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.product-card:hover,
.product-card:focus-visible {
  border-color: var(--teal);
  box-shadow: 0 8px 24px rgba(17, 63, 73, 0.1);
  outline: none;
  transform: translateY(-1px);
}

.product-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.product-card h3,
.product-card p {
  margin: 0;
}

.product-card h3 {
  font-size: 1.08rem;
  line-height: 1.35;
}

.product-card .product-description {
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.product-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
}

.product-link {
  color: var(--teal-dark);
  font-weight: 800;
}

.product-card-actions,
.product-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.product-card-actions .ghost,
.product-card-actions .danger {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.danger {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid #e2bcbc;
  border-radius: 8px;
  background: #fff;
  color: var(--red);
  font-weight: 800;
}

.danger:hover {
  background: #fff3f3;
  border-color: var(--red);
}

.offered-product-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.product-description-field {
  grid-column: 1 / -1;
}

.product-form-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.product-variants-summary {
  color: var(--teal-dark);
  font-size: 0.84rem;
  font-weight: 800;
}

.product-variants-list {
  display: grid;
  gap: 10px;
  min-height: 110px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.product-variant-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.product-variant-entry h3,
.product-variant-entry p {
  margin: 0;
}

.product-variant-entry p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.product-variant-price {
  color: var(--teal-dark);
  font-size: 1rem;
  font-weight: 850;
  white-space: nowrap;
}

.product-variant-actions {
  display: flex;
  gap: 7px;
}

.product-variant-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.product-variant-form {
  display: grid;
  gap: 13px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.product-variant-fields {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr 1.2fr;
  gap: 12px;
  align-items: end;
}

.product-variant-form .modal-actions {
  justify-content: flex-end;
}

.lead-card,
.target-card {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.lead-card header,
.lead-card footer,
.target-card header,
.broker-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.lead-card h3,
.target-card h3,
.broker-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.target-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.target-card p {
  margin: 0;
  line-height: 1.45;
}

.target-card a {
  color: var(--teal-dark);
  font-weight: 800;
}

.target-card.occupied {
  border-color: #d6dce0;
  background: #eef1f2;
  color: var(--muted);
}

.target-card.occupied a {
  color: var(--muted);
}

.tag.occupied {
  border: 1px solid #ccd3d7;
  background: #e1e6e8;
  color: #58636c;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-card,
.task-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.summary-card span,
.summary-card p {
  color: var(--muted);
}

.summary-card strong {
  display: block;
  margin: 5px 0;
  font-size: 1.1rem;
}

.summary-card p,
.task-card p {
  margin: 0;
}

.deliverable-list {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.deliverable-row {
  align-items: center;
  background: var(--surface-soft, #f7f8f7);
  border-radius: 10px;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: minmax(130px, 0.6fr) minmax(180px, 1.4fr) auto;
  padding: 0.75rem;
}

.deliverable-row small {
  grid-column: 2 / -1;
}

.lead-meta {
  margin: 0;
  font-size: 0.9rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tag,
.scope-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef3f4;
  font-size: 0.78rem;
  font-weight: 800;
}

.tag.warn {
  background: #fff4e6;
  color: var(--amber);
}

.tag.locked {
  background: #e9f8fa;
  color: var(--teal-dark);
}

.stage-tag {
  gap: 7px;
  border: 1px solid transparent;
}

.stage-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: currentColor;
}

.stage-reserved {
  border-color: #cfe4e8;
  background: #edf8fa;
  color: #17616b;
}

.stage-qualified {
  border-color: #d8d5f2;
  background: #f2f0ff;
  color: #58519a;
}

.stage-offer {
  border-color: #d6ddf2;
  background: #eef3ff;
  color: #3e5d9b;
}

.stage-negotiation {
  border-color: #f0d7b6;
  background: #fff5e8;
  color: #9a5b16;
}

.stage-won {
  border-color: #cce5c8;
  background: #edf8eb;
  color: #34723a;
}

.stage-lost {
  border-color: #eccaca;
  background: #fff0f0;
  color: #9b3d3d;
}

.stage-control,
.value-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 0 0 10px;
  border-radius: 999px;
  background: #eef3f4;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.stage-select,
.contact-status-select {
  width: auto;
  min-width: 136px;
  min-height: 32px;
  padding: 4px 28px 4px 10px;
  border-radius: 999px;
  border-color: transparent;
  background-color: #fff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.stage-select.compact,
.contact-status-select.compact {
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.contract-value-input,
.product-input {
  width: 124px;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  border-color: transparent;
  background: #fff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.product-input {
  width: 156px;
}

.contract-value-input.compact,
.product-input.compact {
  width: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.product-input.compact {
  width: 154px;
}

.probability {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.bar {
  height: 8px;
  overflow: hidden;
  background: #e5ebee;
  border-radius: 999px;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--lime));
}

.audit-panel {
  padding: 18px;
}

.audit-panel ul {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th,
td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

th {
  color: var(--ink);
  background: #f7fafb;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.broker-kanban-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(240px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.task-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(240px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.kanban-column {
  min-height: 360px;
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.kanban-column h3 {
  margin: 0;
  font-size: 0.88rem;
}

.broker-contact-column {
  min-height: 420px;
}

.compact-card {
  padding: 12px;
}

.broker-kanban-card,
.task-comment-card {
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.broker-kanban-card:hover,
.broker-kanban-card:focus-visible,
.task-comment-card:hover,
.task-comment-card:focus-visible {
  border-color: #9db6bd;
  box-shadow: 0 5px 18px rgba(23, 33, 43, 0.09);
  outline: 0;
  transform: translateY(-1px);
}

.comment-count {
  color: var(--teal-dark);
  font-weight: 800;
}

.compact-card .tag-row {
  gap: 7px;
}

.compact-card .stage-control,
.compact-card .value-control {
  width: 100%;
  justify-content: space-between;
  border-radius: 8px;
  padding: 6px 8px;
}

.compact-card .contact-status-select,
.compact-card .product-input,
.compact-card .contract-value-input {
  width: 142px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.task-card {
  display: grid;
  gap: 10px;
}

.task-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.task-card h3 {
  margin: 0;
  font-size: 0.95rem;
}

.task-card-badges {
  display: flex;
  align-items: center;
  gap: 7px;
}

.task-card label {
  font-size: 0.8rem;
}

.broker-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.broker-card {
  padding: 16px;
}

.broker-card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.broker-form-actions {
  display: flex;
  gap: 8px;
}

#brokerFormError {
  grid-column: 1 / -1;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inline-form .primary {
  min-width: 138px;
}

.access-grid {
  grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.1fr);
  align-items: start;
}

.access-grid .inline-form {
  grid-template-columns: 1fr;
}

.form-error {
  margin: 0;
  color: var(--red);
  font-weight: 800;
}

.broker-card dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin: 16px 0 0;
}

.broker-card dt {
  color: var(--muted);
}

.broker-card dd {
  margin: 0;
  font-weight: 800;
}

.audit-entry {
  padding: 14px 16px;
}

.audit-entry p {
  margin: 6px 0 0;
}

.hidden,
.broker-hidden {
  display: none !important;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(17, 28, 36, 0.42);
}

#leadForm {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.comments-dialog {
  width: min(720px, calc(100vw - 28px));
}

.comments-dialog-shell {
  display: grid;
  gap: 18px;
  max-height: min(820px, calc(100vh - 36px));
  overflow: hidden;
  padding: 22px;
}

.comments-list {
  display: grid;
  gap: 10px;
  min-height: 120px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.comment-entry {
  display: grid;
  gap: 8px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.comment-entry header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.comment-entry time {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.comment-entry p {
  margin: 0;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comment-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.attachment-button {
  min-height: 32px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comment-form {
  display: grid;
  gap: 13px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.file-picker span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.comment-form .modal-actions {
  justify-content: flex-end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.warning {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #f0c27b;
  background: #fff7ea;
  color: #7c4b0c;
  font-weight: 750;
}

output {
  color: var(--teal-dark);
  font-weight: 850;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .metrics,
  .split-layout,
  .broker-grid,
  .product-grid,
  .summary-grid,
  .access-grid,
  .inline-form,
  .offered-product-form {
    grid-template-columns: 1fr;
  }

  .product-variant-fields {
    grid-template-columns: 1fr;
  }

  .kanban-board {
    grid-template-columns: repeat(5, 240px);
  }

  .broker-kanban-board {
    grid-template-columns: repeat(7, 260px);
  }

  .task-board {
    grid-template-columns: repeat(5, 260px);
  }
}

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-heading,
  .topbar-actions,
  .filters,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}
