* {
  box-sizing: border-box;
}

:root {
  --bg-main: #020817;
  --bg-panel: #070d1c;
  --bg-card: #111827;
  --bg-card-soft: #0f172a;
  --bg-input: #111827;
  --border-main: #263b59;
  --border-soft: #334155;
  --text-main: #f8fafc;
  --text-muted: #93c5fd;
  --text-soft: #cbd5e1;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --warning-bg: #2f2512;
  --warning-border: #f59e0b;
  --warning-text: #facc15;
  --danger: #f87171;
}

html[data-theme="light"] {
  --bg-main: #eef7fb;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --bg-card-soft: #e7f1f7;
  --bg-input: #ffffff;
  --border-main: #9fc4d5;
  --border-soft: #bfd5df;
  --text-main: #132033;
  --text-muted: #315f78;
  --text-soft: #40566c;
  --warning-bg: #fff8df;
  --warning-text: #8a5600;
  --danger: #b42318;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

.page-shell {
  min-height: 100vh;
  padding: 14px 18px;
  background: var(--bg-main);
}

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

.top-header h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.top-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.back-btn,
.secondary-btn {
  border: 1px solid var(--border-soft);
  background: var(--bg-card-soft);
  color: var(--text-main);
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 700;
  cursor: pointer;
}

.back-btn:hover,
.secondary-btn:hover {
  background: #162238;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.tab-btn {
  min-width: 86px;
  padding: 9px 18px;
  border: 1px solid var(--border-main);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}

.tab-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 39%;
  gap: 14px;
  align-items: stretch;
}

.left-panel,
.chat-panel {
  border: 1px solid var(--border-main);
  background: var(--bg-panel);
  border-radius: 12px;
  min-height: calc(100vh - 110px);
  max-height: calc(100vh - 110px);
  overflow: hidden;
}

.left-panel {
  overflow-y: auto;
  padding: 12px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.card {
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(38, 59, 89, 0.65);
  padding: 12px 0 16px;
  margin-bottom: 12px;
}

.card:last-child {
  border-bottom: none;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 17px;
  color: var(--text-main);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-row {
  margin-bottom: 12px;
}

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

.field-row label {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-soft);
  background: var(--bg-input);
  color: var(--text-main);
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

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

#businessRequirementText {
  min-height: 120px;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.primary-btn,
#sendChatBtn {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn:hover,
#sendChatBtn:hover {
  background: var(--blue-hover);
}

.primary-btn:disabled,
#sendChatBtn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.status-text {
  color: var(--text-muted);
  font-size: 12px;
}

.hidden {
  display: none;
}

.result-section {
  padding-top: 2px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 140px 160px minmax(250px, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px;
}

.summary-card .label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.summary-card strong {
  font-size: 15px;
  color: var(--text-main);
}

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

.attribute-item {
  border: 1px solid var(--border-main);
  border-radius: 10px;
  padding: 10px;
  background: var(--bg-card);
}

.attribute-title {
  font-weight: 700;
  margin-bottom: 5px;
}

.attribute-meta {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.confirmation-chip {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  font-size: 11px;
  font-weight: 700;
}

.sap-path {
  color: var(--text-soft);
  font-size: 12px;
  margin: 6px 0 10px;
}

.sap-table-wrap {
  overflow: auto;
  border: 1px solid var(--border-main);
  border-radius: 8px;
  background: var(--bg-card);
}

.sap-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 12px;
}

.sap-table thead th {
  background: #1e293b;
  border: 1px solid #334155;
  padding: 8px;
  text-align: left;
  color: var(--text-main);
  white-space: nowrap;
}

.sap-table tbody td {
  border: 1px solid #334155;
  padding: 7px 8px;
  background: #0f172a;
  color: var(--text-soft);
  vertical-align: top;
}

.sap-table tbody tr:nth-child(even) td {
  background: #111c2f;
}

.sap-checkbox {
  display: inline-flex;
  width: 18px;
  height: 18px;
  border: 1px solid #64748b;
  align-items: center;
  justify-content: center;
  background: #020817;
  color: #60a5fa;
  font-weight: 700;
}

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

.unmapped-item {
  padding: 10px;
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
  color: var(--text-main);
  border-radius: 8px;
  font-size: 13px;
}

.test-case-list {
  display: grid;
  gap: 10px;
}

.test-case {
  border: 1px solid var(--border-main);
  border-radius: 8px;
  padding: 10px;
  background: var(--bg-card);
}

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

.chat-panel {
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-main);
}

.chat-header h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

.chat-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: var(--bg-card-soft);
}

.chat-empty {
  color: var(--text-muted);
  font-size: 13px;
}

.chat-msg {
  margin-bottom: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.chat-msg.user {
  background: #172554;
  border: 1px solid #2563eb;
  margin-left: 35px;
}

.chat-msg.ai {
  background: var(--bg-card);
  border: 1px solid var(--border-main);
  margin-right: 18px;
}

.chat-input-row {
  padding: 12px;
  border-top: 1px solid var(--border-main);
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 10px;
  align-items: end;
}

.chat-input-row textarea {
  min-height: 56px;
  max-height: 110px;
}

@media (max-width: 1150px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    min-height: 520px;
    max-height: 700px;
  }

  .summary-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }
}
.chat-row {
    display: flex;
    margin-bottom: 12px;
  }
  
  .chat-row.user {
    justify-content: flex-end;
  }
  
  .chat-row.ai {
    justify-content: flex-start;
  }
  
  .chat-bubble {
    max-width: 92%;
    padding: 11px 12px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--text-main);
    overflow-wrap: anywhere;
  }
  
  .chat-row.user .chat-bubble {
    background: #172554;
    border: 1px solid #2563eb;
  }
  
  .chat-row.ai .chat-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border-main);
  }
  
  .chat-bubble p {
    margin: 0 0 8px;
  }
  
  .chat-bubble p:last-child {
    margin-bottom: 0;
  }
  
  .chat-bubble ul,
  .chat-bubble ol {
    margin: 8px 0 8px 20px;
    padding: 0;
  }
  
  .chat-bubble li {
    margin-bottom: 4px;
  }
  
  .chat-bubble h1,
  .chat-bubble h2,
  .chat-bubble h3,
  .chat-bubble h4 {
    margin: 10px 0 6px;
    line-height: 1.25;
    color: #f8fafc;
  }
  
  .chat-bubble h1 {
    font-size: 18px;
  }
  
  .chat-bubble h2 {
    font-size: 16px;
  }
  
  .chat-bubble h3 {
    font-size: 14px;
  }
  
  .chat-bubble code {
    background: #020817;
    border: 1px solid #334155;
    border-radius: 4px;
    padding: 1px 4px;
    color: #bfdbfe;
    font-size: 12px;
  }
  
  .chat-bubble pre {
    position: relative;
    background: #020817;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 10px 0;
  }
  
  .chat-bubble pre code {
    border: none;
    background: transparent;
    padding: 0;
    color: #dbeafe;
    white-space: pre;
  }
  
  .copy-code-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    border: 1px solid #475569;
    background: #111827;
    color: #e5e7eb;
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
  }
  
  .copy-code-btn:hover {
    background: #1f2937;
  }
  
  .chat-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 12px;
  }
  
  .chat-bubble th,
  .chat-bubble td {
    border: 1px solid #334155;
    padding: 6px 8px;
  }
  
  .chat-bubble th {
    background: #1e293b;
    color: #f8fafc;
  }
  
  .chat-bubble td {
    background: #0f172a;
    color: #cbd5e1;
  }
  .test-case-list {
    display: grid;
    gap: 14px;
  }
  
  .test-case {
    border: 1px solid var(--border-main);
    border-radius: 12px;
    background: var(--bg-card);
    padding: 14px;
  }
  
  .test-case-header {
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-main);
    padding-bottom: 10px;
    margin-bottom: 12px;
  }
  
  .test-case-number {
    background: var(--blue);
    color: #ffffff;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
  }
  
  .test-case h3 {
    margin: 0;
    font-size: 15px;
    color: var(--text-main);
  }
  
  .test-section {
    margin-top: 12px;
  }
  
  .test-section-title {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }
  
  .test-section p {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.5;
  }
  
  .test-step-list,
  .test-issue-list {
    margin: 0;
    padding-left: 22px;
    color: var(--text-soft);
  }
  
  .test-step-list li,
  .test-issue-list li {
    margin-bottom: 6px;
    line-height: 1.5;
  }
  
  .test-step-list li::marker {
    color: #60a5fa;
    font-weight: 700;
  }
  
  .test-issue-list li::marker {
    color: #facc15;
  }
  /* ---------------------------------------------------
   TEST TAB - DISTINCT LEFT PANEL THEME
--------------------------------------------------- */

body:has(#testTab.active) .left-panel {
    background:
      radial-gradient(circle at top left, rgba(37, 99, 235, 0.13), transparent 34%),
      linear-gradient(180deg, #07101f, #071522);
    border-color: #315078;
  }
  
  body:has(#testTab.active) .left-panel .card {
    border-bottom-color: rgba(96, 165, 250, 0.25);
  }
  
  #testTab .card {
    background: transparent;
  }
  
  #testTab .card > h2 {
    font-size: 19px;
    margin-bottom: 4px;
  }
  
  #testTab .muted {
    color: #bfdbfe;
    margin-bottom: 16px;
  }
  
  /* ---------------------------------------------------
     TEST CASE BUBBLES
  --------------------------------------------------- */
  
  .test-case-list {
    display: grid;
    gap: 18px;
  }
  
  .test-bubble {
    position: relative;
    overflow: hidden;
    border: 1px solid #315078;
    border-radius: 18px;
    background:
      linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(8, 20, 38, 0.98));
    box-shadow:
      0 14px 30px rgba(0, 0, 0, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.04);
  }
  
  .test-bubble::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: linear-gradient(180deg, #60a5fa, #2563eb, #22c55e);
  }
  
  .test-bubble-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    align-items: start;
    padding: 16px 18px 14px 20px;
    border-bottom: 1px solid rgba(96, 165, 250, 0.22);
    background:
      linear-gradient(90deg, rgba(37, 99, 235, 0.16), transparent);
  }
  
  .test-number-pill {
    padding: 6px 12px;
    border-radius: 999px;
    background: #2563eb;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.32);
    white-space: nowrap;
  }
  
  .test-bubble-header h3 {
    margin: 0 0 5px;
    color: #f8fafc;
    font-size: 16px;
  }
  
  .test-bubble-header p {
    margin: 0;
    color: #cbd5e1;
    font-size: 12px;
    line-height: 1.5;
  }
  
  .test-bubble-body {
    display: grid;
    gap: 12px;
    padding: 14px 16px 16px 20px;
  }
  
  /* ---------------------------------------------------
     TEST SECTION MINI BLOCKS
  --------------------------------------------------- */
  
  .test-info-block {
    border: 1px solid rgba(71, 85, 105, 0.8);
    border-radius: 14px;
    background: rgba(2, 8, 23, 0.48);
    overflow: hidden;
  }
  
  .test-info-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 11px;
    background: rgba(15, 23, 42, 0.92);
    color: #bfdbfe;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid rgba(71, 85, 105, 0.7);
  }
  
  .test-info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #1e293b;
    color: #93c5fd;
    font-size: 12px;
    font-weight: 800;
  }
  
  .test-info-content {
    padding: 10px 14px 12px;
    color: #e5e7eb;
    font-size: 13px;
    line-height: 1.55;
  }
  
  /* Different bubble accents */
  .test-info-block.preconditions {
    border-color: rgba(96, 165, 250, 0.48);
  }
  
  .test-info-block.steps {
    border-color: rgba(34, 197, 94, 0.48);
  }
  
  .test-info-block.expected {
    border-color: rgba(20, 184, 166, 0.48);
  }
  
  .test-info-block.issues {
    border-color: rgba(245, 158, 11, 0.56);
    background: rgba(47, 37, 18, 0.22);
  }
  
  .test-info-block.fields {
    border-color: rgba(168, 85, 247, 0.48);
  }
  
  .test-info-block.steps .test-info-icon {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
  }
  
  .test-info-block.expected .test-info-icon {
    background: rgba(20, 184, 166, 0.15);
    color: #5eead4;
  }
  
  .test-info-block.issues .test-info-icon {
    background: rgba(245, 158, 11, 0.16);
    color: #facc15;
  }
  
  .test-info-block.fields .test-info-icon {
    background: rgba(168, 85, 247, 0.16);
    color: #d8b4fe;
  }
  
  /* Markdown formatting inside test blocks */
  .test-info-content p {
    margin: 0 0 8px;
  }
  
  .test-info-content p:last-child {
    margin-bottom: 0;
  }
  
  .test-info-content ul,
  .test-info-content ol {
    margin: 0;
    padding-left: 22px;
  }
  
  .test-info-content li {
    margin-bottom: 7px;
  }
  
  .test-info-content li:last-child {
    margin-bottom: 0;
  }
  
  .test-info-content li::marker {
    color: #60a5fa;
    font-weight: 800;
  }
  
  .test-info-block.steps li::marker {
    color: #86efac;
  }
  
  .test-info-block.issues li::marker {
    color: #facc15;
  }
  
  .test-info-content strong {
    color: #ffffff;
  }
  
  .test-info-content code {
    background: #020817;
    border: 1px solid #334155;
    color: #bfdbfe;
    border-radius: 4px;
    padding: 1px 5px;
  }
  
  .test-info-content pre {
    position: relative;
    background: #020817;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
  }
  
  .test-muted {
    color: #94a3b8;
    font-style: italic;
  }
  
  /* Empty state */
  .test-empty-card {
    border: 1px dashed #315078;
    border-radius: 16px;
    padding: 24px;
    background: rgba(15, 23, 42, 0.6);
    text-align: center;
  }
  
  .test-empty-title {
    color: #f8fafc;
    font-weight: 800;
    margin-bottom: 6px;
  }
  
  .test-empty-text {
    color: #bfdbfe;
    font-size: 13px;
  }
  body.test-tab-active .left-panel {
    background:
      radial-gradient(circle at top left, rgba(37, 99, 235, 0.13), transparent 34%),
      linear-gradient(180deg, #07101f, #071522);
    border-color: #315078;
  }
  /* ---------------------------------------------------
   MODERN SCROLLBARS
--------------------------------------------------- */

* {
    scrollbar-width: thin;
    scrollbar-color: #3b82f6 #0f172a;
  }
  
  *::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  
  *::-webkit-scrollbar-track {
    background: #0f172a;
    border-radius: 999px;
  }
  
  *::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #60a5fa, #2563eb);
    border-radius: 999px;
    border: 2px solid #0f172a;
  }
  
  *::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #93c5fd, #3b82f6);
  }
  
  *::-webkit-scrollbar-corner {
    background: #0f172a;
  }
  
  /* Slightly slimmer scrollbars inside panels */
  .left-panel::-webkit-scrollbar,
  .chat-messages::-webkit-scrollbar {
    width: 8px;
  }
  
  .sap-table-wrap::-webkit-scrollbar {
    height: 8px;
  }
  
  /* ---------------------------------------------------
     PROCESSING OVERLAY
  --------------------------------------------------- */
  
  .processing-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background:
      radial-gradient(circle at center, rgba(37, 99, 235, 0.18), transparent 34%),
      rgba(2, 8, 23, 0.78);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .processing-overlay.hidden {
    display: none;
  }
  
  .processing-modal {
    width: min(520px, calc(100vw - 36px));
    border: 1px solid #315078;
    border-radius: 20px;
    background:
      linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(7, 16, 31, 0.98));
    box-shadow:
      0 28px 80px rgba(0, 0, 0, 0.42),
      inset 0 1px 0 rgba(255, 255, 255, 0.05);
    padding: 28px;
    text-align: center;
    color: #f8fafc;
    animation: processingPop 0.18s ease-out;
  }
  
  @keyframes processingPop {
    from {
      opacity: 0;
      transform: translateY(10px) scale(0.98);
    }
  
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }
  
  .processing-spinner {
    width: 58px;
    height: 58px;
    margin: 0 auto 18px;
    border-radius: 50%;
    border: 4px solid rgba(96, 165, 250, 0.18);
    border-top-color: #60a5fa;
    border-right-color: #2563eb;
    animation: processingSpin 0.9s linear infinite;
  }
  
  @keyframes processingSpin {
    to {
      transform: rotate(360deg);
    }
  }
  
  .processing-modal h2 {
    margin: 0 0 10px;
    font-size: 20px;
  }
  
  .processing-modal p {
    margin: 0 auto 18px;
    color: #cbd5e1;
    font-size: 13px;
    line-height: 1.55;
    max-width: 430px;
  }
  
  .processing-steps {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  
  .processing-steps span {
    border: 1px solid rgba(96, 165, 250, 0.28);
    background: rgba(15, 23, 42, 0.82);
    color: #bfdbfe;
    border-radius: 999px;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
  }
