:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #edf3f1;
  --ink: #18211f;
  --muted: #62716d;
  --line: #d8e1de;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --accent: #b7791f;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(22, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf7f5 0%, var(--bg) 44%, #fbfcfb 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  position: relative;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 118px;
  padding: 14px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid #1f3440;
  background: #101d25;
  color: #fff;
  overflow: hidden;
  animation: headerIn 480ms ease-out both;
}

.app-header::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #08a7f7, #7c3aed, transparent);
  opacity: 0.9;
}

.brand-logo {
  grid-column: 1;
  justify-self: start;
  display: block;
  width: clamp(150px, 18vw, 230px);
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.22));
  transform-origin: center;
  animation: logoIn 560ms ease-out both;
  transition: transform 180ms ease, filter 180ms ease;
}

.brand-logo:hover {
  filter: drop-shadow(0 14px 24px rgba(8, 167, 247, 0.22));
  transform: translateY(-1px) scale(1.015);
}

.brand-copy {
  grid-column: 2;
  justify-self: center;
  min-width: 0;
  text-align: center;
  animation: contentIn 560ms ease-out 90ms both;
}

.eyebrow {
  margin: 0 0 6px;
  color: #8bd3ff;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.dataset-pill {
  grid-column: 3;
  justify-self: end;
  flex: 0 0 auto;
  max-width: 290px;
  padding: 8px 11px;
  border: 1px solid rgba(139, 211, 255, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #d7e9f3;
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
  animation: contentIn 520ms ease-out 160ms both;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 20px;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 36px) 36px;
}

.query-panel,
.results-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: panelIn 420ms ease-out both;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.query-panel {
  align-self: start;
  padding: 18px;
}

.results-panel {
  overflow: hidden;
  animation-delay: 80ms;
}

.query-panel:hover,
.results-panel:hover {
  border-color: #c3d5d0;
  box-shadow: 0 16px 36px rgba(22, 35, 31, 0.11);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.results-panel .section-title {
  padding: 18px;
}

.section-title a {
  color: var(--primary-strong);
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
}

.section-title a:hover {
  text-decoration: underline;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding-top: 16px;
}

.field,
.check-field {
  min-width: 0;
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field span,
.check-field span {
  color: #35433f;
  font-size: 0.8rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c8d4d0;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
  transform: translateY(-1px);
}

.check-field {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.check-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.9fr;
  gap: 10px;
}

button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 850;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.primary-button:hover {
  background: var(--primary-strong);
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.2);
  transform: translateY(-1px);
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

.secondary-button:hover:not(:disabled) {
  border-color: #b9c8c4;
  background: #e3ece9;
  transform: translateY(-1px);
}

.rank-note {
  min-height: 44px;
  margin: 16px 0 0;
  padding: 11px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: #fff8eb;
  color: #5f461c;
  font-size: 0.9rem;
  line-height: 1.45;
}

#resultSummary {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.count-box {
  display: grid;
  justify-items: end;
  gap: 1px;
  color: var(--muted);
  font-weight: 800;
}

.count-box span {
  color: var(--primary-strong);
  font-size: 1.65rem;
  line-height: 1;
}

.count-box small {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 220px);
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef5f2;
  color: #384742;
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  color: #25302d;
  font-size: 0.91rem;
  line-height: 1.4;
}

tbody tr:hover {
  background: #f8fbfa;
  transform: translateX(2px);
}

.branch-cell {
  min-width: 280px;
}

.institute-cell {
  min-width: 260px;
  font-weight: 760;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e8f4f2;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.suggestion-badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

tbody tr:hover .suggestion-badge {
  transform: translateY(-1px);
  box-shadow: 0 7px 16px rgba(16, 29, 37, 0.1);
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 800;
}

.suggestion-safe {
  background: #e3f6e8;
  color: #0d6832;
}

.suggestion-moderate {
  background: #fff1cf;
  color: #7a4a02;
}

.suggestion-dream {
  background: #edf0ff;
  color: #3730a3;
}

.margin-good {
  color: #0f6b2f;
  font-weight: 850;
}

.margin-tight {
  color: var(--accent);
  font-weight: 850;
}

.empty-state {
  height: 210px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.error-text {
  color: var(--danger);
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 48px);
  border-top: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--muted);
  font-size: 0.92rem;
  animation: panelIn 420ms ease-out 140ms both;
}

@keyframes headerIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes logoIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes contentIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-footer div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-footer strong {
  color: var(--ink);
}

.app-footer span {
  min-width: 0;
}

.app-footer p {
  margin: 0;
  font-weight: 800;
  white-space: nowrap;
}

.app-footer a {
  color: var(--primary-strong);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: start;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .app-footer,
  .app-footer div {
    align-items: start;
    flex-direction: column;
  }

  .brand-logo,
  .brand-copy {
    align-self: center;
  }

  .brand-copy {
    width: 100%;
    text-align: center;
  }

  h1 {
    font-size: 1.55rem;
  }

  .dataset-pill {
    width: 100%;
    max-width: none;
    text-align: left;
  }

  .control-grid,
  .actions {
    grid-template-columns: 1fr;
  }

  .results-panel .section-title,
  .section-title {
    align-items: start;
    flex-direction: column;
  }

  .count-box {
    justify-items: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
