/* ── Base ── */
:root {
  font-family: Inter, system-ui, sans-serif;
  color: #152033;
  background: #f4f7fb;
}
* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 1040px; margin: auto; padding: 40px 20px 80px; }

/* ── Brand header ── */
header { margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.brand-logo { flex-shrink: 0; }
.eyebrow { font-weight: 800; letter-spacing: .12em; color: #5b61e6; margin: 0; font-size: 13px; }
h1 { font-size: clamp(32px, 6vw, 60px); line-height: 1; margin: .1em 0 0; }
.tagline { color: #4a5568; margin: 0; max-width: 640px; line-height: 1.5; }

/* ── Panels & cards ── */
.panel, #result {
  background: white;
  border: 1px solid #dce3ee;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 10px 35px #1c2c4a12;
  margin: 16px 0;
}

/* ── Form ── */
form { display: flex; gap: 12px; }
input {
  flex: 1; padding: 14px 16px;
  border: 1px solid #bcc8d8; border-radius: 12px; font-size: 16px;
}
input:focus { outline: none; border-color: #5b61e6; box-shadow: 0 0 0 3px #5b61e615; }
button {
  border: 0; border-radius: 12px; padding: 14px 22px;
  background: #171c2b; color: white; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: opacity .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button:not(:disabled):hover { opacity: .85; }
.btn-ghost {
  background: transparent; color: #5b61e6; border: 1px solid #c5c8f5;
  padding: 8px 14px; font-size: 13px; font-weight: 600; border-radius: 10px;
}
.btn-ghost:hover { background: #f0f1ff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-danger { color: #e03; border-color: #fcc; }
.btn-danger:hover { background: #fff0f0; }

/* ── Company card ── */
.company-card {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  background: linear-gradient(135deg, #1a1f35 0%, #2d3561 100%);
  border-radius: 18px; padding: 28px 28px 24px;
  color: white; margin-bottom: 20px;
}
.company-card-body { flex: 1; min-width: 0; }
.company-card h2 { margin: 0 0 6px; font-size: clamp(22px, 4vw, 32px); line-height: 1.1; }
.company-card .company-url {
  display: inline-block; color: #a5d8ff; font-size: 13px; text-decoration: none;
  margin-bottom: 10px; word-break: break-all;
}
.company-card .company-url:hover { text-decoration: underline; }
.company-card .company-summary { margin: 0; color: #c8d3e8; font-size: 14px; line-height: 1.5; }
.company-card-score { text-align: center; flex-shrink: 0; }
.score-circle {
  display: flex; align-items: center; justify-content: center;
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid #5b61e6; font-size: 26px; font-weight: 900;
  background: #ffffff12; margin: 0 auto 6px;
}
.score-circle.high { border-color: #4ade80; color: #4ade80; }
.score-circle.mid  { border-color: #facc15; color: #facc15; }
.score-circle.low  { border-color: #f87171; color: #f87171; }
.score-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: .06em; }

/* ── Export button ── */
.export-row { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.btn-export {
  background: transparent; border: 1px solid #dce3ee; color: #5b61e6;
  border-radius: 10px; padding: 8px 16px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.btn-export:hover { background: #f0f1ff; }

/* ── Tags ── */
.tag {
  display: inline-block; background: #eef0ff; color: #464dcc;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
}

/* ── Grid cards ── */
.hidden { display: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { border: 1px solid #dde4ed; border-radius: 15px; padding: 18px; }
.card h3 { margin: 8px 0 6px; font-size: 15px; }

/* ── History ── */
#history { margin: 16px 0; }
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.history-header h3 { margin: 0; font-size: 15px; color: #4a5568; }
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-radius: 12px; background: white;
  border: 1px solid #dce3ee; margin-bottom: 8px; flex-wrap: wrap;
}
.history-item-info { flex: 1; min-width: 0; }
.history-item-info strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-url { display: block; font-size: 12px; color: #5b61e6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-date { font-size: 11px; color: #94a3b8; }
.history-item-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Chat ── */
#messages {
  max-height: 420px; overflow: auto;
  display: flex; flex-direction: column; gap: 8px; padding: 4px 0; margin-bottom: 12px;
}
.msg { padding: 12px 16px; border-radius: 12px; background: #f0f3f8; line-height: 1.6; overflow-wrap: break-word; word-break: break-word; min-width: 0; }
.msg.user { background: #e9eaff; align-self: flex-end; max-width: 85%; }
.msg.assistant { background: #f0f3f8; align-self: flex-start; max-width: 95%; }
.msg.assistant p { margin: .4em 0; }
.msg.assistant p:first-child { margin-top: 0; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3, .msg.assistant h4 { margin: .7em 0 .3em; font-size: 1em; }
.msg.assistant ul, .msg.assistant ol { margin: .4em 0; padding-left: 1.4em; }
.msg.assistant li { margin: .2em 0; }
.msg.assistant blockquote {
  margin: .5em 0; padding: .5em 1em;
  border-left: 3px solid #5b61e6; background: #f4f5ff; border-radius: 0 8px 8px 0;
}
.msg.thinking { opacity: .6; font-style: italic; display: flex; align-items: center; gap: 8px; }
.msg.assistant table { border-collapse: collapse; width: 100%; margin: .6em 0; font-size: 13px; }
.msg.assistant th, .msg.assistant td { border: 1px solid #c8d3e8; padding: 7px 10px; text-align: left; }
.msg.assistant th { background: #eef0ff; font-weight: 700; color: #152033; }
.msg.assistant tr:nth-child(even) td { background: #f8f9ff; }

/* ── Status & spinner ── */
#status { min-height: 22px; display: flex; align-items: center; gap: 8px; font-size: 14px; color: #4a5568; margin-top: 10px; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2.5px solid #dce3ee; border-top-color: #5b61e6;
  border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Print / PDF ── */
@media print {
  .brand-logo, #history, #chat, .export-row, .btn-export,
  .history-header, button { display: none !important; }
  body { background: white; }
  main { padding: 0; max-width: 100%; }
  .company-card { background: #1a1f35 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .panel, #result { box-shadow: none; border: 1px solid #dce3ee; }
}

@media (max-width: 650px) {
  form { flex-direction: column; }
  .company-card { flex-direction: column; }
}
