:root {
  --bg: #070d1f;
  --bg-soft: #0f1a34;
  --card: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.15);
  --text: #f8fafc;
  --muted: #b2c0d8;
  --accent: #39d3ff;
  --accent-2: #70ffa1;
  --danger: #ff6b81;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Outfit, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, #163867 0%, transparent 35%),
    radial-gradient(circle at 80% 10%, #0e284f 0%, transparent 40%),
    radial-gradient(circle at 50% 90%, #15374f 0%, transparent 30%),
    var(--bg);
  position: relative;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.15;
  background-image: repeating-radial-gradient(circle at 0 0, transparent 0, transparent 2px, rgba(255, 255, 255, 0.08) 3px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.7rem;
}

.topbar p {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.badge {
  border: 1px solid var(--line);
  background: rgba(57, 211, 255, 0.08);
  color: var(--accent);
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  backdrop-filter: blur(8px);
  animation: reveal 0.45s ease both;
}

.panel h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

.help-text {
  margin-top: -0.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-grid {
  display: grid;
  gap: 0.7rem;
  margin: 0.8rem 0;
}

.form-grid.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.three-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: block;
}

label > span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.6rem 0;
}

.checkline > span {
  margin: 0;
}

.dropzone {
  display: block;
  border: 1px dashed rgba(112, 255, 161, 0.6);
  border-radius: 14px;
  text-align: center;
  padding: 1.2rem;
  cursor: pointer;
  background: rgba(112, 255, 161, 0.06);
}

.dropzone input {
  display: none;
}

.inline-fields {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.compact-row {
  flex-wrap: wrap;
}

.compact-row .btn {
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
}

.inline-fields input {
  flex: 1;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font-family: inherit;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  resize: vertical;
  font-family: inherit;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  color: #04233d;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
}

.status {
  margin-top: 0.6rem;
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.kpi-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.03);
}

.kpi-grid h3 {
  margin: 0;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.kpi-grid p {
  margin: 0.3rem 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
}

.actions {
  margin-top: 0.8rem;
}

.score-explain {
  margin-top: 0.75rem;
  line-height: 1.5;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.sheet-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  padding: 0.38rem 0.8rem;
  cursor: pointer;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.84rem;
}

.sheet-tab.active {
  color: #04233d;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.sheet-panel.hidden {
  display: none;
}

.table-wrap {
  overflow: auto;
  max-height: 340px;
}

.table-wrap.tall {
  max-height: 500px;
}

.full-span {
  grid-column: 1 / -1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.4rem;
}

th {
  color: var(--muted);
  font-weight: 500;
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(7, 13, 31, 0.95);
  backdrop-filter: blur(3px);
}

td a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed rgba(57, 211, 255, 0.5);
}

td a:hover {
  color: var(--accent-2);
}

.chat-toggle {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #072643;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(57, 211, 255, 0.35);
}

.chat-panel {
  position: fixed;
  right: 1.2rem;
  bottom: 5.5rem;
  width: min(380px, 92vw);
  height: min(540px, 70vh);
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(6, 18, 42, 0.95);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
}

.chat-panel.hidden {
  display: none;
}

.chat-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.chat-panel header button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg {
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  max-width: 90%;
  line-height: 1.4;
}

.msg.user {
  margin-left: auto;
  background: rgba(57, 211, 255, 0.2);
}

.msg.bot {
  margin-right: auto;
  background: rgba(255, 255, 255, 0.1);
}

#chatForm {
  display: flex;
  gap: 0.4rem;
  padding: 0.8rem;
  border-top: 1px solid var(--line);
}

#chatForm button {
  border: none;
  border-radius: 10px;
  padding: 0 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #05253f;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .compact-row {
    flex-direction: column;
  }

  .form-grid.two-cols,
  .form-grid.three-cols {
    grid-template-columns: 1fr;
  }
}
