:root {
  --panel: #ffffff;
  --ink: var(--text, #1d1d1f);
  --muted: var(--text-secondary, #6e6e73);
  --line: var(--border, rgba(0, 0, 0, 0.08));
  --blue: var(--accent, #0071e3);
  --orange: #f6a13a;
  --green: #19a06f;
  --red: #ed4f4f;
  --paper: #fff9e6;
  --shadow: var(--shadow-md, 0 12px 40px rgba(0, 0, 0, 0.08));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  margin-bottom: 28px;
  text-decoration: none;
}

.brand > div:last-child {
  min-width: 0;
}

.brand strong {
  display: block;
  font-size: 17px;
  white-space: nowrap;
}

.brand span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 12px;
  white-space: nowrap;
}

.nav-group {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid #b9d2ee;
  border-radius: 8px;
  padding: 10px;
}

.nav-group p {
  margin: 4px 8px 10px;
  color: var(--blue);
  font-weight: 700;
}

.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 11px 12px;
  border-radius: 6px;
  color: #20344d;
}

.nav-item.active,
.nav-item:hover {
  background: #d9eafa;
  color: var(--blue);
  font-weight: 700;
}

.context-card {
  margin-top: 18px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #0071e3, #2997ff);
  color: white;
  box-shadow: var(--shadow-sm);
}

.context-card span,
.context-card small {
  display: block;
  color: rgba(255, 255, 255, 0.85);
}

.context-card strong {
  display: block;
  font-size: 26px;
  margin: 6px 0;
  letter-spacing: 0;
}

.main {
  min-width: 0;
  padding: 14px 20px 30px;
}

.product-bar {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 360px auto auto;
  gap: 16px;
  align-items: center;
  margin: -14px -20px 18px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}

.logout-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}

.logout-btn:hover {
  background: rgba(0, 113, 227, 0.08);
}

.breadcrumb {
  color: #54667d;
  font-size: 14px;
}

.global-search {
  position: relative;
  display: block;
}

.global-search span {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #718197;
  font-size: 13px;
  font-weight: 600;
}

.global-search input {
  height: 38px;
  padding-left: 76px;
  padding-right: 12px;
  color: #22344d;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 980px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.global-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: #fff;
}

.search-results.search-results-active {
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.25);
}

.search-row-highlight td {
  background: rgba(0, 113, 227, 0.12) !important;
  animation: searchRowPulse 1.2s ease 2;
}

@keyframes searchRowPulse {
  0%,
  100% {
    background: rgba(0, 113, 227, 0.12);
  }
  50% {
    background: rgba(0, 113, 227, 0.22);
  }
}

.operator {
  min-width: 168px;
  text-align: right;
}

.operator span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.operator strong {
  display: block;
  margin-top: 2px;
  color: #22344d;
  font-size: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 25px;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.panel-header {
  display: flex;
  gap: 12px;
  align-items: center;
}

.primary,
.ghost,
.secondary-action,
.more-action {
  border-radius: 7px;
  padding: 10px 16px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary {
  color: white;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(35, 104, 181, 0.22);
}

.ghost {
  background: white;
  border-color: var(--line);
  color: var(--blue);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.secondary-action,
.more-action {
  min-height: 42px;
  color: #23415f;
  background: #fff;
  border-color: #c4d5e7;
}

.more-action {
  width: 138px;
  padding-right: 10px;
}

.risk-client-select {
  width: 320px;
}

.flow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.step {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  border-radius: 0;
  text-align: left;
  color: var(--ink);
  padding: 10px 14px;
}

.step span {
  width: 46px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #edf4fb;
  color: var(--blue);
  font-weight: 900;
  font-size: 14px;
}

.step strong,
.step em {
  display: block;
  font-style: normal;
}

.step em {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.step.active {
  border-color: transparent;
  background: #edf6ff;
  box-shadow: inset 0 -3px 0 var(--blue);
}

.step.active span {
  background: var(--blue);
  color: white;
}

.status-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.status-board div {
  min-height: 74px;
  padding: 14px 16px;
  border: 1px solid #d9e2ed;
  border-radius: 8px;
  background: #fff;
}

.status-board span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.status-board strong {
  display: block;
  margin-top: 8px;
  color: #1d416b;
  font-size: 24px;
}

.workspace,
.panel {
  min-width: 0;
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(26, 55, 92, 0.08);
  overflow: hidden;
}

.panel.active {
  display: block;
}

.panel-header {
  justify-content: space-between;
  padding: 16px 20px;
  background: #f8fbff;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 22px;
}

.panel-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 14px 18px;
  padding: 18px 20px;
}

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

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

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

label {
  display: grid;
  gap: 6px;
  color: #28364a;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #c6d2df;
  border-radius: 5px;
  background: #fff;
  padding: 8px 10px;
  color: #8b210f;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.hot {
  background: var(--paper);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 0 20px 20px;
}

.section-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #f8fbff;
}

.section-card h3 {
  margin: 0 0 14px;
  color: var(--blue);
}

.section-card label + label {
  margin-top: 12px;
}

.bl-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  padding: 20px;
}

.bl-form {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #f8fbff;
}

.mapping {
  border-radius: var(--radius);
  background: linear-gradient(160deg, #0071e3, #1d3a5c);
  color: white;
  padding: 18px;
}

.mapping h3 {
  margin-top: 0;
}

.mapping ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}

.mapping li {
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  padding-bottom: 12px;
}

.mapping span {
  display: block;
  color: #96c2ef;
  font-size: 13px;
}

.mapping strong {
  display: block;
  margin-top: 4px;
}

.wizard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 14px 20px 0;
}

.wizard span {
  background: #85c5ef;
  color: white;
  padding: 12px 18px;
  font-weight: 800;
  border-radius: 6px;
}

.wizard .done {
  background: var(--orange);
}

.section-title,
.table-title {
  margin: 18px 20px 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: #e5f0fa;
  color: #213851;
  font-weight: 800;
}

.insurer-row,
.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 20px 18px;
}

.insurer {
  min-width: 156px;
  border: 1px solid #d5dde8;
  border-radius: 8px;
  padding: 12px 18px;
  background: white;
  color: #b32414;
  font-weight: 900;
}

.insurer span {
  color: #576577;
}

.insurer.active {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(246, 161, 58, 0.22);
}

.choice-grid label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.choice-grid input {
  width: auto;
}

#screen-insurance > label {
  padding: 0 20px 20px;
}

.policy-card {
  margin: 20px;
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 12px;
}

.policy-card > div {
  border-radius: 8px;
  padding: 18px;
  background: #f8fbff;
  border: 1px solid var(--line);
}

.policy-card span {
  display: block;
  color: var(--muted);
}

.policy-card strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

.policy-status {
  color: white;
  background: linear-gradient(135deg, #6a7787, #243950) !important;
  font-size: 22px;
  font-weight: 900;
}

.policy-status.success {
  background: linear-gradient(135deg, #1eb47a, #137050) !important;
}

pre {
  white-space: pre-wrap;
  min-height: 250px;
  margin: 0;
  color: #173455;
  line-height: 1.55;
}

.log {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 10px;
}

.log li {
  color: #25384f;
}

.payable-table {
  margin: 0 20px 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

.search-bar {
  display: grid;
  grid-template-columns: 220px minmax(260px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
}

.search-bar .ghost {
  height: 42px;
}

.query-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 20px;
}

.search-results {
  margin: 0;
}

.select-row {
  border: 0;
  border-radius: 5px;
  padding: 7px 10px;
  color: white;
  background: var(--blue);
  font-weight: 700;
}

.relation-card {
  border-radius: var(--radius);
  padding: 18px;
  background: linear-gradient(160deg, #0071e3, #1d3a5c);
  color: white;
  min-height: 320px;
}

.relation-card h3 {
  margin: 0 0 14px;
}

.relation-card p {
  color: #bad3ef;
  line-height: 1.6;
}

.relation-line {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.relation-line span {
  color: #96c2ef;
}

.relation-line strong {
  color: white;
  word-break: break-word;
}

.relation-link {
  margin: 16px 0;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  text-align: center;
  font-weight: 900;
}

.status-pill {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 99px;
  color: #0f5138;
  background: #d9f4e8;
  font-weight: 800;
  font-size: 13px;
}

.risk-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 20px;
}

.risk-score-card {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 8px;
  padding: 22px;
  color: white;
  background: linear-gradient(135deg, #1f5f9d, #173453);
}

.risk-score-card span {
  color: #b8d5f1;
  font-weight: 700;
}

.risk-score-card strong {
  margin-top: 10px;
  font-size: 64px;
  line-height: 1;
}

.risk-score-card em {
  width: fit-content;
  margin-top: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-style: normal;
  font-weight: 900;
}

.risk-score-card p {
  margin: 16px 0 0;
  color: #dcecff;
  line-height: 1.6;
}

.risk-score-card.high {
  background: linear-gradient(135deg, #a83a32, #57222a);
}

.risk-score-card.low {
  background: linear-gradient(135deg, #168866, #174b42);
}

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

.risk-metrics div {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #f8fbff;
}

.risk-metrics span {
  display: block;
  color: var(--muted);
}

.risk-metrics strong {
  display: block;
  margin-top: 12px;
  color: #1d416b;
  font-size: 26px;
}

.risk-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 0 20px 20px;
}

.warning-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.warning-list li {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #f3d3ad;
}

.warning-list strong {
  color: #a34e0f;
}

.warning-list span {
  color: #35465d;
  line-height: 1.5;
}

.risk-conclusion {
  display: grid;
  gap: 12px;
}

.risk-conclusion div {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #d8e2ee;
  background: #fff;
  line-height: 1.55;
}

.risk-conclusion strong {
  color: var(--blue);
}

.risk-history {
  margin-top: 0;
}

.payable-table .table-title {
  margin: 0;
  border-radius: 0;
}

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

th,
td {
  border-top: 1px solid #d9e2ed;
  padding: 10px 12px;
  text-align: left;
}

th {
  background: #f0f5fb;
  color: #2b3f59;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  background: #122b4a;
  color: white;
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
}

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

.ai-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
}

.ai-input-panel,
.ai-result-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbff;
  padding: 18px;
}

.ai-input-panel h3,
.ai-result-panel h3 {
  margin: 0 0 12px;
  color: var(--blue);
}

.ai-textarea {
  min-height: 280px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #1d1d1f !important;
}

.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.ai-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.ai-step {
  padding: 10px 8px;
  border-radius: 8px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.ai-step.active {
  background: rgba(0, 113, 227, 0.12);
  color: var(--accent);
}

.ai-step.done {
  background: rgba(25, 160, 111, 0.15);
  color: var(--green);
}

.ai-preview-groups {
  display: grid;
  gap: 12px;
  max-height: 420px;
  overflow-y: auto;
}

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

.ai-preview-group h4 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.ai-field-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 6px 0;
  border-bottom: 1px solid #eef2f6;
  font-size: 13px;
}

.ai-field-row:last-child {
  border-bottom: 0;
}

.ai-field-row.empty strong {
  color: var(--muted);
  font-weight: 500;
}

.ai-confidence {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  background: #e8f8f0;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.ai-confidence.low {
  color: #a34e0f;
  background: #fff7ed;
}

.ai-apply-bar {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ai-banner {
  margin: 0 20px 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(0, 113, 227, 0.08);
  border: 1px solid rgba(0, 113, 227, 0.2);
  color: #0a4d8c;
  font-size: 14px;
}

.ai-parsing .primary {
  opacity: 0.7;
  pointer-events: none;
}

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

  .sidebar {
    position: static;
  }

  .nav-group {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .nav-group p,
  .context-card {
    grid-column: 1 / -1;
  }

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

  .operator {
    text-align: left;
  }

  .split,
  .bl-layout,
  .policy-card,
  .query-layout,
  .risk-layout,
  .risk-content,
  .ai-layout {
    grid-template-columns: 1fr;
  }

  .ai-steps {
    grid-template-columns: repeat(2, 1fr);
  }

  .risk-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .search-bar {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 760px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .flow,
  .form-grid.two,
  .form-grid.three,
  .form-grid.four,
  .wizard,
  .nav-group,
  .search-bar,
  .risk-metrics {
    grid-template-columns: 1fr;
  }

  .risk-client-select {
    width: 100%;
  }
}
