:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --line: #d9e1ea;
  --text: #19212a;
  --muted: #667484;
  --accent: #0b6bcb;
  --accent-strong: #084f97;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --shadow: 0 16px 40px rgba(22, 34, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

button:hover {
  background: var(--accent-strong);
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  min-height: 38px;
  padding: 9px 10px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

small {
  color: var(--muted);
  line-height: 1.5;
}

.topbar {
  align-items: center;
  background: #0f1720;
  color: white;
  display: flex;
  justify-content: space-between;
  min-height: 82px;
  padding: 18px 28px;
}

.topbar h1,
.login-panel h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.eyebrow {
  color: #a6b3c2;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.ghost-button,
.secondary-button {
  background: var(--surface-soft);
  color: var(--text);
}

.ghost-button:hover,
.secondary-button:hover {
  background: #dfe9f3;
}

.app-layout {
  display: grid;
  gap: 22px;
  grid-template-columns: 360px minmax(0, 1fr);
  padding: 22px;
}

.sidebar,
.workspace {
  display: grid;
  gap: 16px;
  align-content: start;
}

.panel,
.results-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel h2,
.results-panel h2 {
  font-size: 16px;
  margin: 0 0 14px;
}

.panel {
  display: grid;
  gap: 12px;
}

.file-drop {
  align-items: center;
  border: 1px dashed #9aa8b7;
  border-radius: 8px;
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 16px;
  text-align: center;
}

.file-drop input {
  display: none;
}

.file-drop span {
  color: var(--accent);
  font-size: 14px;
}

.input-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.rule-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.rule-editor-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 260px;
  overflow: auto;
}

.rule-editor {
  min-width: 0;
  width: 100%;
}

.rule-editor th,
.rule-editor td {
  padding: 7px;
}

.rule-editor th {
  position: sticky;
  top: 0;
}

.rule-editor input,
.rule-editor select {
  min-height: 34px;
  padding: 6px 8px;
}

.rule-editor input[type="checkbox"] {
  min-height: 0;
  width: auto;
}

.rule-editor .keyword-cell {
  min-width: 120px;
}

.rule-editor .score-cell {
  width: 76px;
}

.rule-editor .delete-rule {
  background: #fff1f0;
  color: var(--danger);
  min-height: 34px;
  padding: 0 10px;
}

.rule-editor .delete-rule:hover {
  background: #ffd8d5;
}

.check-line {
  align-items: center;
  color: var(--text);
  display: flex;
  gap: 8px;
}

.check-line input {
  width: auto;
}

.stats-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 6px;
  padding: 16px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stat strong {
  font-size: 28px;
}

.toolbar {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1fr) 160px repeat(4, auto);
}

.save-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  margin-bottom: 12px;
}

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

.saved-item {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) auto auto auto;
  padding: 10px;
}

.saved-item strong {
  display: block;
  font-size: 14px;
}

.saved-item span {
  color: var(--muted);
  font-size: 12px;
}

.section-title {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title span {
  background: #e8f1ff;
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 10px;
}

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

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

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

th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: 13px;
  line-height: 1.45;
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
}

.pill.eligible {
  background: #ecfdf3;
  color: var(--success);
}

.pill.excluded {
  background: #fff1f0;
  color: var(--danger);
}

.pill.winner {
  background: #fff7e6;
  color: var(--warning);
}

.login-page {
  background: #0f1720;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  background: white;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
  max-width: 420px;
  padding: 28px;
  width: 100%;
}

.brand-mark {
  align-items: center;
  background: #0f1720;
  border-radius: 6px;
  color: white;
  display: inline-flex;
  font-weight: 900;
  height: 38px;
  justify-content: center;
  margin-bottom: 18px;
  width: 76px;
}

.login-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 12px;
}

.error-text {
  color: var(--danger);
  min-height: 20px;
}

@media (max-width: 980px) {
  .app-layout,
  .stats-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    gap: 14px;
    flex-direction: column;
  }

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