:root {
  color-scheme: light;
  --bg: #f5f7ff;
  --panel: #ffffff;
  --ink: #15193e;
  --muted: #626b91;
  --line: #dfe4f4;
  --accent: #262b63;
  --accent-2: #6372bc;
  --accent-soft: #e8ecff;
  --warn-soft: #eef1ff;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(24, 30, 75, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(99, 114, 188, 0.14) 0, rgba(245, 247, 255, 0) 280px),
    var(--bg);
  color: var(--ink);
  font-family: Arial, "Helvetica Neue", sans-serif;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

button,
.file-button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 700;
  min-height: 40px;
  box-shadow: 0 6px 16px rgba(38, 43, 99, 0.08);
  transform: translateY(0);
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, color 0.16s ease, filter 0.16s ease, opacity 0.16s ease, transform 0.16s ease;
}

button:hover:not(:disabled),
.file-button:hover {
  background: #1f2457;
  box-shadow: 0 12px 24px rgba(38, 43, 99, 0.18);
  filter: none;
  transform: translateY(-1px);
}

button:active:not(:disabled),
.file-button:active {
  box-shadow: inset 0 3px 8px rgba(9, 13, 42, 0.24), 0 2px 6px rgba(38, 43, 99, 0.12);
  transform: translateY(2px) scale(0.97);
}

button.button-pressed,
.file-button.button-pressed {
  box-shadow: inset 0 3px 8px rgba(9, 13, 42, 0.24), 0 2px 6px rgba(38, 43, 99, 0.12);
  transform: translateY(2px) scale(0.97);
}

button:focus-visible,
.file-button:focus-visible {
  outline: 3px solid rgba(99, 114, 188, 0.32);
  outline-offset: 2px;
}

button:disabled {
  cursor: progress;
  opacity: 0.82;
}

button.button-saving {
  position: relative;
  padding-left: 34px;
}

button.button-saving::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.secondary {
  background: #eef1fb;
  color: var(--ink);
}

.secondary:hover:not(:disabled),
.file-button.secondary:hover {
  background: #dfe5f8;
  color: var(--accent);
}

.danger {
  background: #f7d9d6;
  color: var(--danger);
}

.danger:hover:not(:disabled) {
  background: #efc4bf;
  color: #8d1d14;
}

.muted {
  background: transparent;
  border: 1px solid #e0b4ae;
}

.muted:hover:not(:disabled) {
  background: #fff2f0;
  border-color: #cf8f87;
  color: var(--danger);
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

body.auth-pending .app-shell {
  visibility: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 18%, rgba(99, 114, 188, 0.2), transparent 30%),
    linear-gradient(180deg, rgba(245, 247, 255, 0.96), rgba(232, 236, 255, 0.96));
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 30px;
  border: 1px solid rgba(38, 43, 99, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 28px 70px rgba(24, 30, 75, 0.16);
}

.login-brand {
  color: var(--accent);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 8px;
}

.login-card h1 {
  margin: 0;
  font-size: 30px;
}

.login-card p {
  margin: -6px 0 4px;
  color: var(--muted);
  font-weight: 700;
}

.login-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.login-message {
  min-height: 18px;
  color: var(--danger);
  font-weight: 800;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 18px;
  margin-bottom: 14px;
  border: 1px solid rgba(99, 114, 188, 0.2);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #f0f3ff 100%);
  box-shadow: var(--shadow);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-logo {
  width: clamp(150px, 20vw, 280px);
  height: auto;
  object-fit: contain;
  flex: 0 0 auto;
}

.eyebrow {
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--accent);
  font-size: clamp(24px, 3.2vw, 42px);
  line-height: 1.05;
  white-space: nowrap;
}

h2 {
  font-size: 20px;
}

.topbar-actions,
.toolbar,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-actions {
  align-items: end;
  display: grid;
  grid-template-columns: 142px 142px auto auto auto;
  justify-content: flex-end;
  justify-self: end;
  max-width: 100%;
  min-width: 0;
}

.nav-control-row {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin: 0 0 14px;
}

.as-of-control {
  align-items: stretch;
  display: grid;
  gap: 6px;
  color: var(--accent);
  font-weight: 800;
  min-width: 0;
  width: 142px;
  font-size: 13px;
}

.as-of-control input,
.as-of-control select {
  min-width: 0;
}

.file-button input {
  display: none;
}

.page-tabs {
  display: flex;
  gap: 8px;
  margin: 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-button {
  background: #eef1fb;
  color: var(--accent);
  flex: 0 0 auto;
}

.tab-button:hover:not(.active):not(:disabled) {
  background: #dfe5f8;
  color: var(--accent);
}

.tab-button.active {
  background: var(--accent);
  color: white;
}

.tab-button.active:hover:not(:disabled) {
  background: #1f2457;
}

.page:not(.active) {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 14px;
  display: grid;
  gap: 5px;
  min-height: 104px;
  position: relative;
  overflow: hidden;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.metric span,
.metric small,
.panel-header p {
  color: var(--muted);
}

.period-caption {
  color: var(--accent-2);
  display: block;
  font-weight: 800;
  margin-top: 6px;
}

.metric strong {
  font-size: 24px;
}

.metric:hover {
  background: linear-gradient(135deg, #252a63 0%, #3f4b9b 100%);
  border-color: rgba(99, 114, 188, 0.72);
  box-shadow: 0 20px 44px rgba(24, 30, 75, 0.18);
  transform: translateY(-1px);
}

.metric:hover::before {
  background: linear-gradient(90deg, #b58a33, #eef1ff);
}

.metric:hover span,
.metric:hover small {
  color: rgba(255, 255, 255, 0.78);
}

.metric:hover strong {
  color: #ffffff;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
  align-items: stretch;
}

.dashboard-layout > .panel {
  grid-column: span 2;
}

.panel {
  padding: 14px;
}

.dashboard-layout .panel {
  display: flex;
  flex-direction: column;
  min-height: 330px;
}

.dashboard-layout .panel-header {
  margin-bottom: 8px;
}

.dashboard-layout .panel-header p {
  margin: 4px 0 0;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.with-actions {
  align-items: center;
}

.toolbar {
  margin-bottom: 12px;
}

.toolbar input,
.toolbar select,
.form-grid input,
.form-grid select,
.form-grid textarea,
.entry-form input,
.entry-form select,
.goals-form input,
.goals-form select,
.as-of-control input,
.as-of-control select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  height: 40px;
  min-height: 40px;
  padding: 9px 11px;
  width: 100%;
}

.goal-stepper-field {
  align-items: stretch;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.goal-stepper-controls {
  display: grid;
  gap: 4px;
  grid-template-rows: repeat(2, 1fr);
}

.goal-stepper-btn {
  align-items: center;
  border-radius: 8px;
  display: inline-flex;
  font-size: 15px;
  font-weight: 900;
  justify-content: center;
  min-height: 18px;
  min-width: 32px;
  padding: 0;
}

.form-grid textarea {
  height: auto;
  line-height: 1.45;
  min-height: 82px;
  resize: vertical;
}

.entry-form select {
  line-height: 20px;
}

.topbar-actions button,
.topbar-actions .file-button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-height: 38px;
  min-width: 92px;
  padding: 8px 10px;
  white-space: nowrap;
}

.toolbar input {
  min-width: min(420px, 100%);
  flex: 1;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.customer-toolbar {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 240px) minmax(180px, 220px);
  margin-bottom: 14px;
}

.search-field input,
.customer-sort-field select,
.customer-filter-field select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  height: 40px;
  padding: 9px 11px;
  width: 100%;
}

.customer-sort-field {
  display: grid;
  gap: 6px;
  color: #344140;
  font-weight: 700;
  min-width: 0;
}

.customer-filter-field {
  display: grid;
  gap: 6px;
  color: #344140;
  font-weight: 700;
  min-width: 0;
}

.mini-stat {
  background: #f7f9ff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-height: 66px;
  padding: 10px 12px;
}

.mini-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-stat strong {
  color: var(--accent);
  font-size: 20px;
}

.customer-dashboard-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.customer-kpi-card {
  background:
    linear-gradient(180deg, rgba(102, 117, 191, 0.14), rgba(255, 255, 255, 0) 42%),
    white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(17, 21, 72, 0.06);
  display: grid;
  gap: 5px;
  min-height: 94px;
  padding: 14px 16px;
}

.customer-kpi-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.customer-kpi-card strong {
  color: var(--ink);
  font-size: 25px;
  line-height: 1.08;
}

.customer-kpi-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.customer-insight-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
}

.customer-insight-card {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  min-height: 176px;
  padding: 14px;
}

.insight-head {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.insight-head h3 {
  font-size: 17px;
  margin: 0;
}

.insight-head span {
  background: var(--accent-soft);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  min-width: 30px;
  padding: 4px 9px;
  text-align: center;
}

.customer-insight-list {
  display: grid;
  gap: 8px;
  max-height: 176px;
  overflow-y: auto;
  padding-right: 2px;
}

.customer-insight-item {
  align-items: center;
  background: #f8faff;
  border: 1px solid rgba(216, 222, 242, 0.78);
  border-radius: 8px;
  box-shadow: none;
  color: var(--ink);
  display: grid;
  gap: 4px;
  justify-items: stretch;
  min-height: 48px;
  padding: 9px 10px;
  text-align: left;
}

.customer-insight-item:hover:not(:disabled) {
  background: var(--accent-soft);
  box-shadow: none;
  color: var(--ink);
  transform: translateY(-1px);
}

.customer-insight-item span {
  align-items: center;
  display: flex;
  gap: 7px;
  min-width: 0;
}

.customer-insight-item strong,
.customer-insight-item em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-insight-item strong {
  font-size: 13px;
  line-height: 1.25;
}

.customer-insight-item em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.customer-insight-item small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.policy-insight-item span {
  align-items: start;
  display: grid;
  gap: 2px;
}

.policy-insight-item {
  min-height: 62px;
}

.vip-insight-item {
  background: linear-gradient(135deg, rgba(181, 138, 51, 0.18), rgba(255, 255, 255, 0.78));
  border-color: rgba(181, 138, 51, 0.42);
}

.customer-empty-note {
  align-items: center;
  background: #f8faff;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  font-weight: 800;
  min-height: 54px;
  padding: 10px;
}

.customer-table {
  font-size: 14px;
  min-width: 760px;
  table-layout: fixed;
}

.customer-table th:nth-child(1) {
  width: 42%;
}

.customer-table th:nth-child(2) {
  width: 15%;
}

.customer-table th:nth-child(3) {
  width: 20%;
}

.customer-table th:nth-child(4) {
  width: 15%;
}

.customer-table th:nth-child(5) {
  width: 8%;
}

.link-button {
  background: transparent;
  border-radius: 6px;
  box-shadow: none;
  color: var(--accent);
  display: inline;
  min-height: 0;
  padding: 2px 4px;
  text-align: left;
}

.link-button:hover:not(:disabled) {
  background: var(--accent-soft);
  box-shadow: none;
  color: #111548;
  text-decoration: underline;
  transform: none;
}

.link-button:active:not(:disabled) {
  box-shadow: none;
  transform: scale(0.98);
}

.policy-link {
  font-weight: 900;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-name-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  max-width: 100%;
}

.customer-name-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.customer-header-actions button,
.customer-header-actions .file-button {
  min-height: 42px;
  padding: 9px 14px;
  white-space: nowrap;
}

.vip-tag {
  background: linear-gradient(135deg, #b58a33, #f3d47e);
  border: 1px solid rgba(121, 84, 23, 0.18);
  border-radius: 999px;
  color: #2a1b05;
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: 0;
  padding: 2px 7px;
}

.vip-tag-list {
  align-items: center;
  display: inline-flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 4px;
}

.family-vip-tag {
  background: linear-gradient(135deg, #252a63, #7784d6);
  border-color: rgba(37, 42, 99, 0.22);
  color: white;
}

.customer-group-row {
  cursor: pointer;
}

.customer-group-row.vip-customer-row {
  background: linear-gradient(90deg, rgba(181, 138, 51, 0.2), rgba(255, 255, 255, 0.92) 50%);
  box-shadow: inset 4px 0 0 #b58a33;
}

.customer-group-row.vip-customer-row strong,
.customer-group-row.vip-customer-row .customer-name-button {
  color: #141741;
}

.customer-group-row.expanded {
  background: #f8faff;
}

.compact-action {
  min-height: 34px;
  min-width: 54px;
  padding: 6px 10px;
}

.customer-policy-detail-row > td {
  background: #fbfcff;
  padding: 0;
}

.customer-policy-detail {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding: 14px;
}

.vip-policy-detail {
  background: linear-gradient(135deg, rgba(181, 138, 51, 0.12), rgba(255, 255, 255, 0.58));
}

.customer-policy-profile {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(190px, 0.8fr) minmax(0, 2fr);
}

.customer-policy-profile article {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 10px 12px;
}

.customer-policy-profile span,
.policy-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.customer-policy-profile strong,
.policy-card strong {
  color: var(--ink);
  font-size: 14px;
  overflow-wrap: anywhere;
}

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

.policy-card {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(150px, 1.2fr) minmax(90px, 0.6fr) minmax(110px, 0.7fr) auto;
  padding: 10px 12px;
}

.policy-card > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.policy-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.policy-actions {
  justify-content: end;
}

.customer-name-cell,
.customer-status,
.clip-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-status {
  display: block;
  max-width: 100%;
}

.customer-pagination {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 12px;
}

.pagination-summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.pagination-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.pagination-actions button {
  background: #f1f4fc;
  color: var(--ink);
  min-height: 34px;
  min-width: 36px;
  padding: 6px 10px;
}

.pagination-actions button.active {
  background: var(--accent);
  color: white;
}

.pagination-actions button:disabled {
  cursor: default;
  opacity: 0.45;
  transform: none;
}

.pagination-ellipsis {
  color: var(--muted);
  font-weight: 900;
  padding: 0 2px;
}

.customer-dialog {
  width: min(960px, calc(100% - 28px));
}

.customer-detail-dialog {
  width: min(920px, calc(100% - 28px));
}

.family-dialog {
  width: min(760px, calc(100% - 28px));
}

.family-rename-dialog {
  width: min(520px, calc(100% - 28px));
}

.dialog-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin: 10px 0 0;
}

.dialog-note strong {
  color: var(--accent);
}

.family-manager {
  display: grid;
  gap: 12px;
}

.family-list {
  display: grid;
  gap: 10px;
  max-height: min(56vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.family-row {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
}

.family-row strong {
  color: var(--ink);
  font-size: 16px;
}

.family-row span,
.family-row small {
  color: var(--muted);
  display: block;
  font-weight: 800;
  line-height: 1.4;
}

.family-row small {
  font-size: 12px;
  margin-top: 3px;
}

.family-member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.family-member-chip {
  align-items: center;
  background: #f3f5fd;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  gap: 6px;
  min-height: 30px;
  padding: 4px 10px;
}

.family-member-chip b {
  color: var(--muted);
  font-size: 11px;
  font-weight: 1000;
  line-height: 1;
}

.family-member-add {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 10px;
}

.family-member-add input {
  min-width: 0;
}

.customer-detail-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.customer-detail-grid article {
  background: #f8faff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-height: 74px;
  padding: 10px 12px;
}

.customer-detail-grid article.wide {
  grid-column: 1 / -1;
}

.customer-detail-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.customer-detail-grid strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.customer-detail-actions {
  grid-template-columns: 1fr auto auto;
}

.customer-address-field {
  grid-column: 1 / -1;
}

.form-field {
  display: grid;
  gap: 6px;
  color: #344140;
  font-weight: 700;
  min-width: 0;
}

.customer-name-field,
.customer-family-field {
  grid-column: 1 / -1;
}

.customer-family-field small,
.customer-family-label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  margin-top: 5px;
}

.customer-family-label {
  margin-top: 3px;
}

.inline-family-button {
  justify-self: start;
  margin-top: 8px;
  min-height: 34px;
  padding: 6px 12px;
}

.customer-name-suggestions {
  background: #f8faff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.customer-name-suggestions[hidden],
.customer-match-status[hidden] {
  display: none;
}

.customer-suggestion-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.customer-suggestion {
  background: white;
  border: 1px solid #d9def1;
  box-shadow: none;
  color: var(--ink);
  display: grid;
  gap: 3px;
  justify-items: start;
  min-height: 0;
  padding: 10px 12px;
  text-align: left;
}

.customer-suggestion:hover:not(:disabled) {
  background: #eef2ff;
  border-color: #c5ceef;
  color: var(--accent);
}

.customer-suggestion span,
.customer-suggestion small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.customer-match-status {
  align-items: center;
  background: #eef7f1;
  border: 1px solid #cfe7d6;
  border-radius: 8px;
  color: #244d32;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  padding: 8px 10px;
}

.customer-match-status span {
  font-size: 12px;
  line-height: 1.4;
}

.customer-match-status .link-button {
  background: transparent;
  box-shadow: none;
  color: #244d32;
  min-height: 0;
  padding: 0;
}

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

.agents-table {
  font-size: 12px;
  min-width: 0;
  table-layout: fixed;
}

.unit-table {
  font-size: 12px;
  min-width: 0;
  table-layout: fixed;
}

.unit-table th,
.unit-table td {
  padding: 4px 2px;
}

.unit-table tbody tr {
  height: 36px;
}

.unit-layout .table-wrap {
  min-height: 520px;
}

.unit-table th {
  font-size: 12px;
}

.unit-table th:nth-child(1) {
  width: 10%;
}

.unit-table th:nth-child(2) {
  width: 18%;
}

.unit-table th:nth-child(3) {
  width: 14%;
}

.unit-table th:nth-child(4),
.unit-table th:nth-child(5),
.unit-table th:nth-child(6) {
  width: 10%;
}

.unit-table th:nth-child(7) {
  width: 8%;
}

.unit-table th:nth-child(3),
.unit-table th:nth-child(4),
.unit-table th:nth-child(5),
.unit-table th:nth-child(6),
.unit-table td:nth-child(3),
.unit-table td:nth-child(4),
.unit-table td:nth-child(5),
.unit-table td:nth-child(6) {
  text-align: center;
}

.unit-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-table .row-actions button {
  font-size: 10px;
  min-height: 24px;
  width: 24px;
}

.unit-actions {
  gap: 3px;
  justify-content: flex-end;
}

.unit-fyc-list-table {
  min-width: 0;
  table-layout: fixed;
}

.unit-fyc-list-table th:nth-child(3),
.unit-fyc-list-table td:nth-child(3) {
  text-align: center;
}

.compact-table table {
  min-width: 860px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f0f3ff;
  color: var(--accent);
  font-size: 13px;
  white-space: nowrap;
}

.agents-table th,
.agents-table td {
  line-height: 1.35;
  padding: 8px 10px;
  vertical-align: middle;
  white-space: nowrap;
}

.agents-table th {
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.agents-table th:nth-child(1) {
  width: 16%;
}

.agents-table th:nth-child(2) {
  width: 22%;
}

.agents-table th:nth-child(3) {
  width: 14%;
}

.agents-table th:nth-child(4) {
  width: 10%;
}

.agents-table th:nth-child(5) {
  width: 16%;
}

.agents-table th:nth-child(6) {
  width: 8%;
}

.agents-table th:nth-child(7) {
  width: 10%;
}

.agents-table th:nth-child(8) {
  width: 4%;
}

.agents-table {
  min-width: 1180px;
  table-layout: fixed;
}

tbody tr:hover {
  background: #fbfcff;
}

tbody tr.mdrt-row {
  background:
    linear-gradient(90deg, rgba(181, 138, 51, 0.28), rgba(255, 247, 222, 0.72) 38%, rgba(246, 248, 255, 0.96)),
    #fff8e6;
  box-shadow: inset 5px 0 0 #b58a33, inset 0 1px 0 rgba(181, 138, 51, 0.28), inset 0 -1px 0 rgba(181, 138, 51, 0.22);
}

tbody tr.mdrt-row:hover {
  background:
    linear-gradient(90deg, rgba(181, 138, 51, 0.36), rgba(255, 243, 202, 0.85) 38%, rgba(241, 244, 255, 0.98)),
    #fff3ca;
}

tbody tr.mdrt-row td {
  border-bottom-color: rgba(181, 138, 51, 0.32);
}

tbody tr.mdrt-row .agent-name strong {
  color: #15193e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

tbody tr.selected-agent-row {
  box-shadow: inset 4px 0 0 var(--accent);
}

tbody tr.selected-agent-row:not(.mdrt-row) {
  background: #f5f7ff;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.agent-name {
  cursor: pointer;
  min-width: 0;
  white-space: nowrap;
}

.agent-identity-cell {
  cursor: pointer;
}

.agent-two-line {
  display: grid;
  gap: 2px;
  min-height: 34px;
  min-width: 0;
  grid-template-rows: repeat(2, minmax(0, auto));
}

.agent-text-line {
  align-items: center;
  display: flex;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-identity-inline {
  align-items: center;
  display: flex;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.agent-identity-inline strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-code {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-name-stack {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.agent-name-stack strong {
  overflow: visible;
  overflow-wrap: anywhere;
  white-space: normal;
}

.agent-metric-line {
  text-align: right;
}

.agent-metric-line .agent-text-line {
  justify-content: flex-end;
}

.agent-renewal-line {
  text-align: left;
}

.agent-renewal-note,
.agent-muted {
  color: var(--muted);
  font-size: 11px;
}

.agent-nickname {
  max-width: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-code {
  width: 6.5%;
}

.col-name {
  width: 12%;
}

.col-nickname {
  width: 4.5%;
}

.col-date {
  width: 6%;
}

.col-license {
  width: 5%;
}

.col-license-number {
  width: 7.2%;
}

.col-role {
  width: 4.5%;
}

.col-status {
  width: 5.5%;
}

.col-money {
  width: 5.2%;
}

.col-case {
  width: 3.5%;
}

.col-active-month {
  width: 5.5%;
}

.col-tenure {
  width: 3.5%;
}

.col-renewal {
  width: 6%;
}

.col-commission {
  width: 6%;
}

.col-actions {
  width: 5.5%;
}

.date-chip {
  display: inline-block;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.pill.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.new {
  background: var(--warn-soft);
  color: #4352a3;
}

.pill.prospect {
  background: #fff4d9;
  color: #8a5a00;
}

.pill.suspended {
  background: #fff4d9;
  color: #8a5a00;
}

.pill.terminated {
  background: #eceff0;
  color: #657170;
}

.qualification-list {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
}

.qualification {
  background: #eef1fb;
  border: 1px solid #d9def3;
  border-radius: 999px;
  color: var(--accent);
  display: inline-flex;
  font-size: 10px;
  font-weight: 800;
  padding: 4px 7px;
  white-space: nowrap;
}

.onboarding-table {
  margin-top: 16px;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.agents-table .row-actions button {
  font-size: 11px;
  min-height: 28px;
  width: 28px;
}

.agents-table .row-actions {
  flex-wrap: nowrap;
  justify-content: center;
}

.agents-table .agent-actions-cell {
  vertical-align: middle;
}

.entry-form {
  display: grid;
  grid-template-columns: minmax(132px, 0.72fr) minmax(220px, 1.25fr) repeat(4, minmax(104px, 0.68fr)) minmax(140px, 0.92fr) auto;
  gap: 12px;
  align-items: end;
  padding: 0;
}

.entry-form button {
  justify-self: start;
  min-width: 118px;
  white-space: nowrap;
}

@media (max-width: 1280px) {
  .app-shell {
    padding-top: 28px;
  }

  .nav-control-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .page-tabs {
    display: grid;
    grid-template-columns: repeat(7, minmax(106px, 1fr));
    overflow-x: visible;
  }

  .tab-button {
    min-height: 42px;
    padding: 8px 10px;
  }

  .topbar-actions {
    grid-template-columns: 150px 150px repeat(4, minmax(96px, auto));
    justify-content: end;
    justify-self: stretch;
  }

  .entry-form {
    grid-template-columns: minmax(132px, 0.8fr) minmax(250px, 1.4fr) repeat(4, minmax(108px, 0.74fr));
  }

  .entry-form label:nth-of-type(7) {
    grid-column: span 4;
  }

  .entry-form button {
    grid-column: span 2;
    justify-self: stretch;
    min-height: 40px;
  }

  .customer-toolbar {
    grid-template-columns: minmax(240px, 1fr) minmax(170px, 220px) minmax(170px, 220px);
  }
}

.entry-agent-field {
  grid-column: auto;
}

.agent-chart-panel {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.entry-money-field,
.entry-case-field {
  min-width: 0;
}

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

.goals-form button {
  grid-column: 1 / -1;
}

.settings-block {
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.settings-block h3 {
  color: var(--accent);
  font-size: 18px;
  margin: 0;
}

.settings-fields {
  display: grid;
  gap: 12px;
}

.settings-two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.goal-inline-group {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.goal-smart-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.goal-smart-tools button {
  grid-column: auto;
}

.full-field {
  grid-column: 1 / -1;
}

.unit-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.unit-summary {
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 14px;
}

.unit-summary span,
.unit-summary small {
  color: var(--muted);
  font-weight: 800;
}

.unit-summary strong {
  color: var(--accent);
  font-size: 24px;
}

.unit-form,
.unit-fyc-form {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: 14px;
  padding: 0;
}

.unit-fyc-table {
  margin-bottom: 14px;
}

.unit-form input,
.unit-form select,
.unit-fyc-form input,
.unit-fyc-form select {
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 40px;
  padding: 9px 11px;
  width: 100%;
}

.unit-layout {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
}

.unit-tree-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.unit-tree,
.unit-tree ul {
  display: grid;
  gap: 10px;
}

.unit-tree ul {
  border-left: 2px solid var(--line);
  list-style: none;
  margin: 10px 0 0 14px;
  padding-left: 14px;
}

.tree-node {
  background: #f8faff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 10px;
}

.tree-node span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.root-node {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.root-node span {
  color: #eef1fb;
}

.segment-grid {
  display: block;
}

.date-chip {
  color: var(--muted);
  font-size: 13px;
}

.date-chip.renewal-warning,
.date-chip.renewal-urgent {
  border-radius: 999px;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  padding: 3px 7px;
  white-space: nowrap;
}

.date-chip.renewal-warning {
  background: #fff3ca;
  color: #8a620c;
}

.date-chip.renewal-urgent {
  background: #f8d9d4;
  color: #a4392d;
}

.row-actions button,
.icon-button {
  width: 38px;
  min-height: 34px;
  padding: 0;
}

.goal-bars,
.segment-list,
.checklist-summary,
.rank-list,
.monthly-chart {
  display: grid;
  gap: 12px;
}

.dashboard-layout .goal-bars,
.dashboard-layout .rank-list,
.dashboard-layout .segment-list {
  flex: 1;
}

.dashboard-layout .goal-bars,
.dashboard-layout .rank-list {
  align-content: space-between;
  gap: 8px;
}

.dashboard-layout .rank-list {
  align-content: start;
  gap: 7px;
}

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

.onboarding-summary-grid article {
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.onboarding-summary-grid span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
}

.onboarding-summary-grid strong {
  color: var(--ink);
  display: block;
  font-size: 24px;
  line-height: 1.1;
  margin-top: 6px;
}

.onboarding-accordion {
  display: grid;
  gap: 8px;
}

.onboarding-detail {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.onboarding-detail summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
}

.onboarding-detail summary::-webkit-details-marker {
  display: none;
}

.onboarding-detail summary span,
.onboarding-detail summary strong {
  color: var(--accent);
  font-weight: 900;
}

.onboarding-detail > .bar {
  margin-top: 10px;
}

.onboarding-step-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.prospect-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.prospect-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.prospect-card-head,
.prospect-card-foot {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.prospect-card-head strong {
  color: var(--ink);
  display: block;
  font-size: 17px;
}

.prospect-card-head span,
.prospect-card-foot span,
.prospect-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.prospect-card-head b {
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
}

.prospect-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.prospect-meta span {
  background: #f4f6ff;
  border-radius: 999px;
  padding: 4px 8px;
}

.goal-row,
.segment-row,
.rank-row,
.check-row {
  display: grid;
  gap: 8px;
}

.rank-row {
  border-radius: 8px;
  padding: 2px 0;
}

.rank-row.mdrt-rank-row {
  background:
    linear-gradient(90deg, rgba(181, 138, 51, 0.28), rgba(255, 247, 222, 0.72) 40%, rgba(246, 248, 255, 0.96)),
    #fff8e6;
  box-shadow: inset 5px 0 0 #b58a33, inset 0 1px 0 rgba(181, 138, 51, 0.28), inset 0 -1px 0 rgba(181, 138, 51, 0.22);
  padding: 10px 12px;
}

.rank-row.mdrt-rank-row strong {
  color: #15193e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.goal-label,
.segment-label,
.rank-label,
.check-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

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

.bar span {
  display: block;
  height: 100%;
  width: var(--value);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.chart-mode-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -6px 0 10px;
}

.segment-mode-toggle {
  justify-content: flex-end;
  margin: 4px 0 8px;
}

.chart-mode-toggle button {
  background: #eef1fb;
  color: var(--accent);
  min-height: 30px;
  min-width: 62px;
  padding: 6px 10px;
}

.chart-mode-toggle button:hover:not(.active):not(:disabled) {
  background: #dfe5f8;
  color: var(--accent);
}

.chart-mode-toggle button.active {
  background: var(--accent);
  color: #ffffff;
}

.chart-mode-toggle button.active:hover:not(:disabled) {
  background: #1f2457;
}

.combo-chart-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.combo-chart {
  display: block;
  min-width: 680px;
  width: 100%;
}

.chart-grid {
  stroke: #e6ebf7;
  stroke-width: 1;
}

.chart-axis,
.chart-axis-title,
.chart-month {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.left-axis {
  text-anchor: end;
}

.right-axis {
  text-anchor: start;
}

.left-title {
  fill: var(--accent);
  text-anchor: start;
}

.chart-axis-line {
  stroke: #d9def3;
  stroke-width: 1.5;
}

.chart-month {
  fill: var(--accent);
  text-anchor: middle;
}

.chart-bar {
  cursor: default;
}

.chart-fyp {
  fill: var(--accent);
}

.chart-fyc {
  fill: var(--accent-2);
}

.chart-cases {
  fill: #b58a33;
}

.chart-caseSize {
  fill: #8b6f2d;
}

.chart-tooltip {
  background: var(--ink);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(21, 25, 62, 0.2);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
  pointer-events: none;
  position: fixed;
  white-space: nowrap;
  z-index: 20;
}

.save-toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 1200;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border: 1px solid rgba(38, 43, 99, 0.14);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  box-shadow: 0 18px 44px rgba(20, 24, 58, 0.18);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.save-toast-mark {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(38, 43, 99, 0.1);
}

.save-toast-copy {
  display: grid;
  gap: 3px;
}

.save-toast strong {
  font-size: 14px;
  line-height: 1.25;
}

.save-toast small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.save-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.save-toast[data-type="success"] {
  border-left-color: #176b52;
}

.save-toast[data-type="success"] .save-toast-mark {
  background: #176b52;
  box-shadow: 0 0 0 5px rgba(23, 107, 82, 0.12);
}

.save-toast[data-type="warning"] {
  border-left-color: #b05c12;
}

.save-toast[data-type="warning"] .save-toast-mark {
  background: #b05c12;
  box-shadow: 0 0 0 5px rgba(176, 92, 18, 0.12);
}

.empty-state {
  color: var(--muted);
  font-weight: 800;
  padding: 8px 0;
}

.segment-row {
  padding: 13px;
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segment-pie-wrap {
  align-content: stretch;
  align-items: center;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(180px, 1fr) auto;
  gap: clamp(8px, 1.4vw, 14px);
  min-height: 100%;
}

.segment-pie {
  align-items: center;
  aspect-ratio: 1;
  align-self: center;
  background: var(--pie);
  border-radius: 50%;
  display: grid;
  justify-self: center;
  max-width: clamp(176px, 58%, 236px);
  min-width: clamp(150px, 34vw, 176px);
  padding: 12px;
  position: relative;
  width: min(100%, 236px);
}

.segment-pie::after {
  background: #ffffff;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
  content: "";
  inset: 22%;
  position: absolute;
}

.segment-pie > div {
  position: relative;
  text-align: center;
  z-index: 1;
}

.segment-pie-tooltip-layer {
  inset: 0;
  position: absolute;
  z-index: 2;
}

.segment-pie-hit {
  cursor: default;
  fill: rgba(255, 255, 255, 0);
  pointer-events: all;
}

.segment-pie-hit:hover {
  fill: rgba(255, 255, 255, 0.16);
}

.segment-pie span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 900;
}

.segment-pie strong {
  color: var(--ink);
  display: block;
  font-size: 18px;
  line-height: 1.1;
  margin-top: 4px;
}

.segment-legend {
  align-self: end;
  display: grid;
  gap: 6px;
}

.segment-legend-row {
  align-items: center;
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 4px 8px;
  min-height: 48px;
  padding: 6px 9px;
}

.segment-dot {
  background: var(--dot);
  border-radius: 50%;
  height: 10px;
  width: 10px;
}

.segment-legend-row strong {
  color: var(--ink);
  min-width: 0;
}

.segment-legend-row b {
  color: var(--accent);
  font-size: 15px;
}

.segment-legend-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  grid-column: 2 / -1;
}

.compact-segment-row,
.compact-goal-row,
.compact-rank-row {
  min-height: 48px;
}

.compact-segment-row,
.compact-goal-row {
  padding: 6px 9px;
}

.compact-goal-row small,
.compact-segment-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-rank-row {
  min-height: 40px;
  padding: 2px 0;
}

.compact-rank-row.mdrt-rank-row {
  min-height: 46px;
  padding: 6px 9px;
}

.compact-rank-row .rank-label span,
.compact-goal-row .goal-label span,
.compact-segment-row .segment-label span {
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

dialog {
  width: min(780px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
  background: rgba(16, 24, 24, 0.45);
}

form {
  padding: 20px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.icon-button {
  background: #eef2f0;
  color: var(--ink);
  border-radius: 50%;
  font-size: 24px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #344140;
  font-weight: 700;
  min-width: 0;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 16px 0 0;
  padding: 12px;
}

legend {
  padding: 0 8px;
  font-weight: 800;
}

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

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.check-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 12px;
}

.check-group h3 {
  color: var(--accent);
  font-size: 14px;
  margin: 0 0 10px;
}

.check-group-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.checkbox-line {
  align-items: center;
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.checks input,
.checkbox-line input {
  width: 18px;
  height: 18px;
}

[data-former-agent-only][hidden] {
  display: none !important;
}

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  margin-top: 18px;
}

@media (max-width: 980px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
    display: grid;
  }

  .dashboard-layout > .panel {
    grid-column: auto;
  }

  .customer-toolbar {
    grid-template-columns: 1fr;
  }

  .customer-dashboard-grid,
  .customer-insight-grid {
    grid-template-columns: 1fr 1fr;
  }

  .customer-policy-profile,
  .policy-card {
    grid-template-columns: 1fr;
  }

  .customer-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions {
    justify-content: flex-start;
  }

  .customer-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-control-row {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    grid-template-columns: 142px 142px auto auto auto;
    justify-content: start;
  }

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

  .entry-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segment-grid {
    display: block;
  }

  .segment-pie-wrap {
    grid-template-columns: 1fr;
  }

  .segment-pie {
    max-width: clamp(180px, 46vw, 220px);
    min-width: 150px;
  }

  .unit-layout,
  .unit-summary-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 16px;
  }

  .summary-grid,
  .onboarding-summary-grid,
  .prospect-card-grid,
  .form-grid,
  .checks,
  .entry-form,
  .goals-form,
  .unit-form,
  .unit-fyc-form {
    grid-template-columns: 1fr;
  }

  .check-group-items {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .toolbar {
    align-items: stretch;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex-basis: auto;
  }

  .page-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .customer-detail-grid {
    grid-template-columns: 1fr;
  }

  .customer-dashboard-grid,
  .customer-insight-grid {
    grid-template-columns: 1fr;
  }

  .brand-logo {
    width: min(180px, 38vw);
  }

  h1 {
    font-size: clamp(20px, 6vw, 28px);
  }

  .topbar-actions > *,
  .toolbar > *,
  .as-of-control {
    width: 100%;
  }
}

/* Responsive refinement layer */
@media (max-width: 1280px) {
  .topbar-actions {
    grid-template-columns: repeat(6, minmax(104px, 1fr));
  }
}

@media (max-width: 1100px) {
  .app-shell {
    padding: 18px;
  }

  .topbar {
    align-items: stretch;
  }

  .brand-title {
    flex-wrap: wrap;
  }

  h1 {
    white-space: normal;
  }

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

  .dashboard-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-layout > .panel {
    grid-column: span 1;
  }

  .dashboard-layout > .panel:last-child {
    grid-column: 1 / -1;
  }

  .entry-form {
    grid-template-columns: minmax(140px, 0.8fr) minmax(260px, 1.4fr) repeat(3, minmax(110px, 0.7fr));
  }

  .entry-form label:nth-of-type(6),
  .entry-form label:nth-of-type(7),
  .entry-form button {
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .topbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
  }

  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .dashboard-layout > .panel,
  .dashboard-layout > .panel:last-child {
    grid-column: auto;
  }

  .dashboard-layout .panel {
    min-height: auto;
  }

  .segment-pie-wrap {
    grid-template-rows: minmax(220px, auto) auto;
  }

  .segment-pie {
    width: min(52vw, 240px);
  }

  .unit-summary-grid,
  .customer-dashboard-grid,
  .customer-insight-grid,
  .onboarding-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .customer-policy-profile,
  .policy-card {
    grid-template-columns: 1fr;
  }

  .policy-actions,
  .row-actions {
    justify-content: flex-start;
  }

  .customer-policy-profile article,
  .policy-card {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    padding: 12px;
  }

  .topbar {
    padding: 14px;
  }

  .brand-title {
    gap: 10px;
  }

  .brand-logo {
    width: min(220px, 70vw);
  }

  .nav-control-row {
    gap: 10px;
  }

  .page-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab-button {
    min-height: 40px;
    padding: 8px;
    white-space: normal;
  }

  .topbar-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions button,
  .topbar-actions .file-button {
    min-width: 0;
  }

  .summary-grid,
  .unit-summary-grid,
  .customer-dashboard-grid,
  .customer-insight-grid,
  .onboarding-summary-grid,
  .goals-form,
  .unit-form,
  .unit-fyc-form,
  .form-grid,
  .entry-form {
    grid-template-columns: 1fr;
  }

  .metric,
  .customer-kpi-card,
  .unit-summary {
    min-height: auto;
  }

  .panel {
    padding: 12px;
  }

  .panel-header,
  .panel-header.with-actions,
  .with-actions {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel-header button,
  .with-actions button {
    justify-self: stretch;
  }

  .chart-mode-toggle,
  .segment-mode-toggle {
    justify-content: stretch;
  }

  .chart-mode-toggle button {
    flex: 1 1 0;
    min-width: 0;
  }

  .segment-pie-wrap {
    grid-template-rows: auto auto;
  }

  .segment-pie {
    max-width: 220px;
    min-width: 150px;
    width: min(68vw, 220px);
  }

  .segment-legend-row {
    grid-template-columns: 10px minmax(0, 1fr) auto;
  }

  .entry-form label,
  .entry-form label:nth-of-type(6),
  .entry-form label:nth-of-type(7),
  .entry-form button {
    grid-column: auto;
  }

  .settings-two-col,
  .settings-three-col,
  .goal-inline-group {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar input {
    min-width: 0;
  }

  .combo-chart-wrap {
    margin-inline: -4px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .combo-chart {
    min-width: 680px;
  }

  dialog,
  .customer-dialog,
  .customer-detail-dialog,
  .family-dialog {
    max-height: calc(100dvh - 20px);
    width: min(100% - 16px, 960px);
  }

  dialog form {
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
    padding: 16px;
  }

  .dialog-header {
    align-items: center;
    gap: 10px;
  }

  .dialog-actions,
  .customer-detail-actions {
    grid-template-columns: 1fr;
  }

  .dialog-actions button,
  .customer-detail-actions button {
    width: 100%;
  }

  .check-group-items {
    grid-template-columns: 1fr;
  }

  .family-row {
    grid-template-columns: 1fr;
  }

  .family-row .row-actions {
    justify-content: start;
  }

  .family-member-add {
    grid-template-columns: 1fr;
  }

  .customer-detail-grid {
    grid-template-columns: 1fr;
  }

  .customer-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .pagination-actions {
    justify-content: flex-start;
  }

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

  /* Keep agents table horizontal on embedded narrow viewports */
  .agents-table {
    display: table;
    min-width: 1120px;
    table-layout: fixed;
    width: max-content;
  }

  .agents-table thead {
    display: table-header-group;
  }

  .agents-table tbody {
    display: table-row-group;
  }

  .agents-table tr {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    display: table-row;
    margin-bottom: 0;
    overflow: visible;
    padding: 0;
  }

  .agents-table th,
  .agents-table td {
    border-bottom: 1px solid var(--line);
    display: table-cell;
    padding: 8px 10px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
    width: auto;
  }

  .customer-table,
  .customer-table thead,
  .customer-table tbody,
  .customer-table tr,
  .customer-table td,
  .unit-table,
  .unit-table thead,
  .unit-table tbody,
  .unit-table tr,
  .unit-table td,
  .unit-fyc-list-table,
  .unit-fyc-list-table thead,
  .unit-fyc-list-table tbody,
  .unit-fyc-list-table tr,
  .unit-fyc-list-table td,
  .entry-list-table,
  .entry-list-table thead,
  .entry-list-table tbody,
  .entry-list-table tr,
  .entry-list-table td {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .customer-table thead,
  .unit-table thead,
  .unit-fyc-list-table thead,
  .entry-list-table thead {
    display: none;
  }

  .customer-table tr,
  .unit-table tr,
  .unit-fyc-list-table tr,
  .entry-list-table tr {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(24, 30, 75, 0.05);
    height: auto;
    margin-bottom: 10px;
    overflow: hidden;
    padding: 10px;
  }

  .customer-table td,
  .unit-table td,
  .unit-fyc-list-table td,
  .entry-list-table td {
    border-bottom: 0;
    padding: 6px 0;
    text-align: left;
    white-space: normal;
  }

  .customer-table td:nth-child(2)::before,
  .customer-table td:nth-child(3)::before,
  .customer-table td:nth-child(4)::before,
  .unit-table td:nth-child(3)::before,
  .unit-table td:nth-child(4)::before,
  .unit-table td:nth-child(5)::before,
  .unit-table td:nth-child(6)::before,
  .unit-fyc-list-table td:nth-child(3)::before,
  .entry-list-table td:nth-child(1)::before,
  .entry-list-table td:nth-child(2)::before,
  .entry-list-table td:nth-child(3)::before,
  .entry-list-table td:nth-child(4)::before,
  .entry-list-table td:nth-child(5)::before,
  .entry-list-table td:nth-child(6)::before,
  .entry-list-table td:nth-child(7)::before {
    color: var(--muted);
    display: block;
    font-size: 11px;
    font-weight: 900;
    margin-bottom: 2px;
  }

  .customer-table td:nth-child(2)::before { content: "จำนวน"; }
  .customer-table td:nth-child(3)::before { content: "วันเกิด"; }
  .customer-table td:nth-child(4)::before { content: "เบี้ยรวม"; }
  .unit-table td:nth-child(3)::before { content: "FYC YTD"; }
  .unit-table td:nth-child(4)::before { content: "ตำแหน่ง"; }
  .unit-table td:nth-child(5)::before { content: "ระดับชั้น"; }
  .unit-table td:nth-child(6)::before { content: "ต้นสังกัด"; }
  .unit-fyc-list-table td:nth-child(3)::before { content: "FYC"; }
  .entry-list-table td:nth-child(1)::before { content: "วันที่"; }
  .entry-list-table td:nth-child(2)::before { content: "ตัวแทน"; }
  .entry-list-table td:nth-child(3)::before { content: "FYP"; }
  .entry-list-table td:nth-child(4)::before { content: "FYP MDRT"; }
  .entry-list-table td:nth-child(5)::before { content: "FYC"; }
  .entry-list-table td:nth-child(6)::before { content: "Case"; }
  .entry-list-table td:nth-child(7)::before { content: "หมายเหตุ"; }

  .customer-policy-detail-row {
    padding: 0 !important;
  }

  .customer-policy-detail-row > td {
    padding: 0;
  }

  .customer-policy-detail {
    padding: 10px;
  }

  .agent-metric-line .agent-text-line,
  .number {
    text-align: left;
  }

  .row-actions,
  .unit-actions,
  .policy-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 10px;
  }

  .topbar-actions,
  .page-tabs {
    grid-template-columns: 1fr;
  }

  .brand-logo {
    width: min(210px, 82vw);
  }

  .metric strong,
  .customer-kpi-card strong,
  .unit-summary strong {
    font-size: 22px;
  }

  .segment-pie {
    width: min(76vw, 200px);
  }
}
