:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #121723;
  --muted: #657085;
  --line: #dfe5ef;
  --soft: #eef2f7;
  --blue: #2563eb;
  --green: #0f766e;
  --orange: #f97316;
  --red: #dc2626;
  --violet: #7c3aed;
  --shadow: 0 18px 46px rgba(18, 23, 35, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f6f7fb 0%, #eef2f7 100%);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.auth-overlay {
  align-items: center;
  background: rgba(246, 247, 251, 0.94);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 20;
}

.auth-overlay.active {
  display: flex;
}

.login-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-width: 420px;
  padding: 24px;
  width: 100%;
}

.login-card h2 {
  font-size: 24px;
  margin: 0;
}

.login-card p {
  line-height: 1.45;
}

.auth-error {
  color: var(--red);
  font-size: 13px;
  font-weight: 750;
  min-height: 18px;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin: 0 auto 18px;
  max-width: 1440px;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  align-items: center;
  background: #333436;
  border-radius: 8px;
  display: flex;
  flex: 0 0 auto;
  height: 56px;
  justify-content: center;
  overflow: hidden;
  padding: 6px 10px;
  width: 196px;
}

.brand-logo img {
  display: block;
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.login-card .brand-logo {
  height: 64px;
  margin-bottom: 8px;
  width: 224px;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  margin: 0;
}

p {
  color: var(--muted);
  margin: 5px 0 0;
}

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

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1440px;
}

.control-panel,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  display: grid;
  gap: 18px;
  padding: 18px;
}

.result-panel {
  min-width: 0;
  padding: 18px;
}

.field-block {
  display: grid;
  gap: 8px;
}

label,
legend {
  color: #273044;
  font-size: 13px;
  font-weight: 700;
}

input[type="text"],
input[type="search"],
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  outline: none;
  padding: 10px 12px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.two-col {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.range-label {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

output {
  background: var(--soft);
  border-radius: 999px;
  color: #273044;
  font-size: 13px;
  font-weight: 800;
  min-width: 40px;
  padding: 4px 10px;
  text-align: center;
}

input[type="range"] {
  accent-color: var(--green);
  width: 100%;
}

.type-grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  padding: 14px;
}

.type-grid label {
  align-items: center;
  display: flex;
  font-weight: 650;
  gap: 8px;
}

.type-grid input {
  accent-color: var(--green);
  height: 16px;
  width: 16px;
}

.sample-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.sample-box p {
  font-size: 13px;
  line-height: 1.4;
}

.file-input {
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 9px;
  width: 100%;
}

.sample-list {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 6px;
}

.sample-list div {
  align-items: center;
  background: var(--soft);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  min-height: 34px;
  padding: 7px 9px;
}

.primary-button,
.ghost-button,
.tab-button {
  align-items: center;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
  white-space: nowrap;
}

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

.primary-button:hover,
.ghost-button:hover,
.tab-button:hover {
  transform: translateY(-1px);
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: #253047;
}

.full {
  width: 100%;
}

.metric-strip {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 76px;
  padding: 12px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 750;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: 21px;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 0 -18px;
  padding: 0 18px 14px;
}

.segmented {
  background: var(--soft);
  border-radius: 8px;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
}

.tab-button {
  background: transparent;
  color: #334155;
  min-height: 34px;
  padding: 7px 12px;
}

.tab-button.active {
  background: #fff;
  border-color: var(--line);
}

.filter-input {
  max-width: 210px;
}

.view-pane {
  display: none;
  padding-top: 14px;
}

.view-pane.active {
  display: block;
}

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

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

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

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

td:first-child,
th:first-child {
  width: 42px;
}

.query-cell {
  font-weight: 760;
  line-height: 1.45;
  min-width: 280px;
}

.intent-cell,
.reason-cell {
  color: #3b465a;
  line-height: 1.45;
}

.type-chip {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 850;
  padding: 5px 9px;
  white-space: nowrap;
}

.chip-reformulation {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.chip-implicit {
  background: rgba(15, 118, 110, 0.13);
  color: #0f766e;
}

.chip-related {
  background: rgba(249, 115, 22, 0.13);
  color: #c2410c;
}

.chip-comparative {
  background: rgba(124, 58, 237, 0.12);
  color: #6d28d9;
}

.chip-entity {
  background: rgba(220, 38, 38, 0.11);
  color: #b91c1c;
}

.chip-personalized {
  background: rgba(22, 163, 74, 0.13);
  color: #15803d;
}

.pattern-grid {
  display: grid;
  gap: 14px;
}

.pattern-browser {
  display: grid;
  gap: 14px;
  grid-template-columns: 280px minmax(0, 1fr);
}

.seed-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.seed-button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 5px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.seed-button.active {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.11);
}

.seed-button strong {
  overflow-wrap: anywhere;
}

.seed-button span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.pattern-detail {
  min-width: 0;
}

.pattern-heading,
.pattern-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.pattern-heading {
  margin-bottom: 12px;
}

.pattern-heading h3,
.pattern-item h3 {
  font-size: 16px;
  margin: 0;
}

.pattern-heading p,
.pattern-item p {
  line-height: 1.45;
  margin: 0;
}

.pattern-summary {
  background: #f8fafc;
}

.pattern-seed h3 {
  overflow-wrap: anywhere;
}

.pattern-stat {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.pattern-stat strong {
  font-size: 20px;
}

.history-list {
  display: grid;
  gap: 10px;
}

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

.history-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.history-main strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.history-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 8px;
}

.history-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.toast {
  background: #121723;
  border-radius: 8px;
  bottom: 20px;
  color: #fff;
  font-weight: 750;
  left: 50%;
  min-width: 180px;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  text-align: center;
  transform: translate(-50%, 18px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

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

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .toolbar,
  .top-actions,
  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-block {
    align-items: flex-start;
  }

  .brand-logo {
    height: 52px;
    width: min(196px, 62vw);
  }

  .login-card .brand-logo {
    height: 58px;
    width: min(224px, 72vw);
  }

  .top-actions,
  .toolbar-actions,
  .action-row {
    width: 100%;
  }

  .top-actions button,
  .toolbar-actions button,
  .action-row button {
    width: 100%;
  }

  .two-col,
  .type-grid,
  .metric-strip,
  .pattern-grid,
  .pattern-browser,
  .history-item {
    grid-template-columns: 1fr;
  }

  .filter-input {
    max-width: none;
  }
}
