/* =========================================================
   ZAI Purchasing Copilot - style.css V16
   Target HTML:
   - .app-shell
   - .topbar
   - .layout
   - .list-panel
   - .detail-panel
   - .ai-panel

   Desktop:
     [Pending PR] [PR Detail] [AI Recommendation]

   Mobile:
     stacked vertical layout
   ========================================================= */

:root {
  --bg-start: #eef4ff;
  --bg-end: #f8fbff;
  --card: #ffffff;
  --line: #dbe4f0;
  --text: #172033;
  --muted: #64748b;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --dark: #2f3b52;
  --green: #15803d;
  --red: #c62828;
  --orange: #d97706;
  --shadow: 0 12px 30px rgba(22, 36, 70, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: linear-gradient(120deg, var(--bg-start), var(--bg-end));
}

body {
  overflow-x: hidden;
}

button,
input {
  font-family: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* =========================================================
   Shell / Header
   ========================================================= */

.app-shell {
  width: 100%;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 28px 14px;
}

.eyebrow {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.product-environment {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.topbar h1 {
  margin: 8px 0 0;
  color: #071a36;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 800;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* =========================================================
   Desktop Layout - 핵심 가로 3단
   ========================================================= */

.layout {
  display: grid;
  grid-template-columns: 330px minmax(520px, 1fr) 360px;
  gap: 20px;
  padding: 0 28px 24px;
  align-items: stretch;
  width: 100%;
}

.list-panel {
  grid-column: 1;
  min-width: 0;
}

.detail-panel {
  grid-column: 2;
  min-width: 0;
}

.ai-panel {
  grid-column: 3;
  min-width: 0;
}

/* =========================================================
   Panel common
   ========================================================= */

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

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

/* =========================================================
   Buttons
   ========================================================= */

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 800;
}

.btn.secondary {
  background: var(--dark);
  color: #fff;
}

.btn.primary {
  background: var(--blue);
  color: #fff;
}

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

.btn.approve {
  background: var(--green);
  color: #fff;
}

.btn.reject {
  background: var(--red);
  color: #fff;
}

/* =========================================================
   Pending PR List
   ========================================================= */

.pr-list {
  height: calc(100vh - 230px);
  min-height: 520px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
}

.pr-card {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  padding: 14px;
  text-align: left;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: 0.15s ease;
}

.pr-card:hover {
  border-color: #9ab8ff;
  transform: translateY(-1px);
}

.pr-card.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.10);
}

.pr-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pr-card-top strong {
  font-size: 14px;
}

.pr-card-top span {
  color: var(--blue);
  font-weight: 900;
  white-space: nowrap;
}

.pr-desc {
  margin-top: 8px;
  color: #24324a;
  font-size: 14px;
}

.pr-meta {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.empty-mini {
  padding: 90px 12px;
  color: var(--muted);
  text-align: center;
}

/* =========================================================
   PR Detail
   ========================================================= */

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 12px;
}

.empty-state h3 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 20px;
}

.empty-state p {
  margin: 0;
  line-height: 1.6;
}

.detail-content {
  padding: 18px;
}

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

.summary-card > div {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fff;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 16px;
  font-weight: 900;
}

.section-title {
  margin: 18px 0 10px;
  font-size: 16px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

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

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 800;
}

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

.approval-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* =========================================================
   AI Recommendation
   ========================================================= */

.ai-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
}

.risk-badge.low {
  background: var(--green);
}

.risk-badge.medium {
  background: var(--orange);
}

.risk-badge.high {
  background: var(--red);
}

.risk-badge.neutral {
  background: #64748b;
}

.ai-empty {
  padding: 55px 20px;
  text-align: center;
  color: var(--muted);
}

.ai-orb {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-weight: 900;
  border-radius: 50%;
  box-shadow: 0 18px 35px rgba(37, 99, 235, 0.28);
}

.ai-empty h3 {
  margin: 0 0 10px;
  color: var(--text);
}

.ai-empty p {
  margin: 0;
  line-height: 1.6;
}

.ai-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  min-height: 0;
}

.ai-score-card,
.ai-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fff;
}

.ai-score-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-score-card span {
  color: var(--muted);
  font-weight: 800;
}

.ai-score-card strong {
  color: var(--blue);
  font-size: 30px;
  font-weight: 900;
}

.ai-block h3 {
  margin: 10px 0 0;
  font-size: 21px;
  font-weight: 900;
}

.ai-block p {
  margin: 10px 0 0;
  color: #34445f;
  line-height: 1.6;
}

.check-list {
  margin: 10px 0 0;
  padding-left: 20px;
  color: #34445f;
  line-height: 1.55;
  font-size: 14px;
}


/* =========================================================
   Price Analysis
   ========================================================= */

.price-analysis-block,
.vendor-analysis-block,
.contract-analysis-block,
.budget-analysis-block,
.explain-decision-block {
  background: #fbfdff;
}

.price-title-row,
.analysis-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.price-title-row .risk-badge,
.analysis-title-row .risk-badge {
  min-width: 76px;
  height: 28px;
  font-size: 12px;
}

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

.price-grid > div,
.analysis-grid > div {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.price-grid span,
.analysis-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.price-grid strong,
.analysis-grid strong {
  display: block;
  margin-top: 6px;
  color: #172033;
  font-size: 14px;
  font-weight: 900;
  word-break: break-word;
}

.price-recommendation,
.analysis-recommendation {
  margin: 12px 0 0;
  color: #34445f;
  line-height: 1.55;
  font-size: 14px;
}

.risk-badge.unknown,
.risk-badge.error {
  background: #64748b;
}

/* =========================================================
   Chat
   ========================================================= */

.chat-box {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

.chat-messages {
  min-height: 180px;
  max-height: 310px;
  overflow-y: auto;
  padding: 12px;
  background: #fff;
}

.chat-message {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 16px;
  margin-bottom: 10px;
  line-height: 1.45;
  font-size: 14px;
  white-space: pre-wrap;
}

.chat-message.assistant {
  background: #edf4ff;
  color: #1f2937;
  border-bottom-left-radius: 6px;
}

.chat-message.user {
  margin-left: auto;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--line);
}

#chatInput {
  flex: 1 1 auto;
  min-width: 0;
  height: 48px;
  border: 1px solid #cfd8e6;
  border-radius: 14px;
  padding: 0 14px;
  font-size: 15px;
  outline: none;
}

#chatInput:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

#btnChat {
  width: 72px;
  min-width: 72px;
  height: 48px;
}

/* =========================================================
   Toast
   ========================================================= */

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #0f172a;
  color: #fff;
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  z-index: 3000;
}

.toast.error {
  background: var(--red);
}

/* =========================================================
   Tablet
   ========================================================= */

@media (max-width: 1180px) and (min-width: 769px) {
  .layout {
    grid-template-columns: 300px minmax(420px, 1fr);
  }

  .list-panel {
    grid-column: 1;
  }

  .detail-panel {
    grid-column: 2;
  }

  .ai-panel {
    grid-column: 1 / -1;
  }

  .ai-content {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-box {
    grid-column: 1 / -1;
  }
}

/* =========================================================
   Mobile only
   ========================================================= */

@media (max-width: 768px) {
  html,
  body {
    font-size: 14px;
    overflow-x: hidden;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: rgba(246, 249, 254, 0.96);
    backdrop-filter: blur(10px);
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }

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

  .topbar h1 {
    font-size: 22px;
  }

  .top-actions {
    justify-content: flex-end;
  }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    border-radius: 16px;
  }

  .pr-list {
    height: auto;
    min-height: 0;
    max-height: 260px;
  }

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

  table {
    min-width: 680px;
  }

  th,
  td {
    white-space: nowrap;
  }

  .approval-actions {
    justify-content: stretch;
  }

  .approval-actions .btn {
    flex: 1 1 0;
    min-height: 46px;
  }

  .ai-content {
    padding: 14px;
  }

  .ai-score-card strong {
    font-size: 28px;
  }

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

  .chat-messages {
    min-height: 300px;
    max-height: 42vh;
  }

  .chat-input-row {
    position: sticky;
    bottom: 0;
    z-index: 1000;
    padding: 12px 10px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  #chatInput {
    height: 58px;
    font-size: 16px;
    border-radius: 18px;
  }

  #btnChat {
    width: 66px;
    min-width: 66px;
    height: 58px;
    border-radius: 18px;
  }
}

/* =========================================================
   Small Mobile
   ========================================================= */

@media (max-width: 420px) {
  .topbar h1 {
    font-size: 20px;
  }

  .layout {
    padding: 8px;
    gap: 10px;
  }

  .summary-card {
    grid-template-columns: 1fr;
  }

  .pr-list {
    max-height: 230px;
  }

  .chat-messages {
    min-height: 320px;
  }

  #btnChat {
    width: 60px;
    min-width: 60px;
  }
}

/* V3 Contract Analysis */
.contract-analysis-block,
.budget-analysis-block,
.explain-decision-block { background: #fbfdff; }


/* V4.1 Explain Decision */
.explain-btn {
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 10px;
}

.explain-decision-block {
  background: #fbfdff;
}

#explainText {
  white-space: pre-wrap;
}


/* =========================================================
   V4.2 Korean I18N
   ========================================================= */

.lang-select {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  outline: none;
}

.lang-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
