:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #65727c;
  --line: #d9e0e4;
  --teal: #126a72;
  --teal-dark: #0d4f55;
  --amber: #b66a22;
  --green: #2f7d53;
  --blue: #315c9a;
  --soft: #eef4f4;
  --danger: #a83c3c;
  font-family: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(23, 32, 38, 0.12);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.login-hint {
  color: var(--muted);
  font-size: 13px;
  background: #fbfcfc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

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

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

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.user-pill {
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #ffffff;
  white-space: nowrap;
}

.status-row {
  padding: 12px 18px 0;
  background: var(--bg);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand-lockup.compact {
  gap: 10px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: #ffffff;
  font-weight: 850;
  font-size: 15px;
  letter-spacing: 0;
  box-shadow: inset 0 -10px 18px rgba(13, 79, 85, 0.22);
}

.brand-lockup.compact .brand-mark {
  width: 40px;
  height: 40px;
  font-size: 13px;
}

.product {
  color: var(--teal);
  font-weight: 800;
  letter-spacing: 0;
  font-size: 13px;
}

h1 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.2;
}

.status {
  min-width: 180px;
  max-width: 48vw;
  border-left: 3px solid var(--teal);
  padding: 8px 12px;
  color: var(--muted);
  background: var(--soft);
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status.error {
  border-color: var(--danger);
  color: var(--danger);
  background: #fff1f1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  min-height: calc(100vh - 118px);
  height: auto;
}

.source-panel {
  display: none !important;
}

.admin-view {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.3fr);
  gap: 18px;
  padding: 18px;
}

.admin-card {
  min-height: 260px;
}

.admin-card.wide {
  grid-column: 1 / -1;
}

.admin-card:last-child {
  grid-column: 1 / -1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 2px rgba(23, 32, 38, 0.05);
}

.ai-panel {
  min-height: calc(100vh - 154px);
  width: 100%;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 750;
  font-size: 16px;
}

.counter {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.tab {
  min-height: 34px;
  border: 0;
  background: #f7f9fa;
  color: var(--muted);
  cursor: pointer;
}

.tab + .tab {
  border-left: 1px solid var(--line);
}

.tab.active {
  background: var(--teal);
  color: white;
  font-weight: 700;
}

button.active {
  background: var(--teal);
  color: white;
}

.tab-page {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.tab-page.active {
  display: flex;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #31414b;
  font-weight: 650;
}

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

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

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(18, 106, 114, 0.12);
}

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

details {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 650;
}

details label {
  margin-top: 10px;
}

.action-row {
  display: flex;
  gap: 10px;
}

button {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: white;
  border-radius: 6px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 720;
  min-height: 38px;
}

button:hover {
  background: var(--teal-dark);
}

button.secondary {
  background: white;
  color: var(--teal);
}

button.secondary:hover,
button.ghost:hover {
  background: var(--soft);
}

.top-actions button.active {
  background: var(--teal);
  color: white;
}

button.ghost {
  border: 0;
  color: var(--blue);
  background: transparent;
  min-height: 28px;
  padding: 4px 6px;
}

button.wide {
  width: 100%;
  background: var(--amber);
  border-color: var(--amber);
}

button.wide:hover {
  background: #93531a;
}

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

.hidden {
  display: none !important;
}

.notice {
  border: 1px solid #d9e3d5;
  background: #f4faf3;
  color: var(--green);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 13px;
  line-height: 1.45;
}

.source-config {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
}

.file-drop {
  border: 1px dashed #9cafb8;
  background: #f9fbfb;
  min-height: 84px;
  justify-content: center;
  align-items: center;
  text-align: center;
  border-radius: 7px;
  color: var(--muted);
  padding: 14px;
}

.file-drop input {
  border: 0;
  padding: 8px 0 0;
  background: transparent;
}

.field-tools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.mini-actions {
  display: flex;
  gap: 4px;
}

.field-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  align-content: start;
  gap: 4px 8px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 170px;
  max-height: 30vh;
  padding: 8px;
  resize: vertical;
}

.field-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: center;
  padding: 5px 4px;
  color: #26363f;
  font-weight: 500;
  font-size: 13px;
  min-width: 0;
  border-radius: 6px;
}

.field-item:hover {
  background: #f5f8f8;
}

.field-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-item input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.result-list {
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  min-height: 320px;
  flex: 1;
}

.result-item {
  border-left: 3px solid var(--green);
  padding: 9px 10px;
  background: #f7fbf8;
  border-radius: 6px;
  margin-bottom: 8px;
}

.result-head {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.candidate-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  border: 1px solid #cfe3d8;
  border-radius: 999px;
  background: #eef6f2;
  color: var(--green);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.result-head strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-link {
  color: var(--blue);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  text-decoration: none;
}

.candidate-link:hover {
  text-decoration: underline;
}

.muted-link {
  color: #8a969e;
  font-weight: 600;
}

.candidate-score {
  color: var(--green);
  font-weight: 800;
  white-space: nowrap;
}

.result-item > span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tag-line {
  margin-top: 5px;
  color: var(--blue) !important;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  max-height: none;
}

.chat-messages {
  flex: 0 1 auto;
  min-height: 360px;
  max-height: min(56vh, 620px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  width: min(92%, 880px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  box-shadow: 0 1px 1px rgba(23, 32, 38, 0.04);
}

.chat-bubble.user {
  align-self: flex-end;
  background: #eef6f2;
  border-color: #cfe3d8;
}

.chat-bubble.assistant {
  align-self: flex-start;
}

.chat-bubble strong {
  display: block;
  margin-bottom: 5px;
  color: #26363f;
  font-size: 13px;
}

.chat-bubble span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.excel-card {
  width: min(100%, 980px);
}

.excel-card-note {
  color: var(--amber) !important;
}

.excel-preview {
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  max-height: 260px;
}

.excel-preview table {
  min-width: 620px;
}

.excel-preview th {
  position: static;
  background: #1f4d5a;
  color: #ffffff;
}

.excel-preview td {
  background: #f7fbfc;
}

.excel-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.excel-card-actions span {
  color: var(--muted);
  font-size: 12px;
}

.excel-card-actions button {
  white-space: nowrap;
}

.analysis-panel,
.feedback-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

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

.accuracy-meter span,
.analysis-grid b,
.feedback-title {
  color: #31414b;
  font-size: 13px;
  font-weight: 750;
}

.accuracy-meter strong {
  color: var(--green);
  font-size: 26px;
  line-height: 1;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.analysis-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf9;
  padding: 9px;
}

.analysis-grid b,
.analysis-grid span {
  display: block;
}

.analysis-grid span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.analysis-panel p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.feedback-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.feedback-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.feedback-buttons button.active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.feedback-panel textarea {
  min-height: 76px;
}

.selected-fields,
.fine-print {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.check-line {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  color: #31414b;
}

.check-line input {
  width: 16px;
  height: 16px;
  padding: 0;
}

.account-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 120px auto;
  gap: 10px;
}

.admin-table-wrap {
  min-height: 220px;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 14px;
}

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

.metric strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}

.inline-button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
  margin: 2px;
}

.action-cell {
  min-width: 210px;
  white-space: normal;
}

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

.selected-fields {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fbfcfc;
}

.export-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 0.6fr) minmax(170px, 0.35fr);
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.export-toolbar button.wide {
  min-height: 38px;
}

.export-fields-page,
.export-template-page {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
}

.export-fields-page .selected-fields {
  min-height: 40px;
  margin-top: 10px;
  background: white;
}

.output-fields-text {
  min-height: 240px;
  line-height: 1.55;
  resize: vertical;
  font-family: inherit;
}

.export-summary {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.export-summary strong {
  color: #31414b;
}

.preview-wrap {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.preview-title {
  font-weight: 750;
}

.table-scroll {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 160px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  max-width: 190px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  background: #edf3f4;
  z-index: 1;
}

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

  .panel {
    min-height: 420px;
  }

  .ai-panel {
    min-height: 760px;
  }

  .admin-view {
    grid-template-columns: 1fr;
  }

  .account-form,
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    height: auto;
    padding: 16px;
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .status {
    max-width: 100%;
    width: 100%;
  }

  .workspace {
    padding: 12px;
  }

  .inline-fields,
  .export-toolbar,
  .field-tools,
  .account-form,
  .metric-grid,
  .analysis-grid,
  .feedback-buttons {
    grid-template-columns: 1fr;
  }

  .action-row {
    flex-direction: column;
  }

  .chat-shell {
    min-height: 460px;
    max-height: none;
  }

  .chat-messages {
    min-height: 300px;
  }

  .result-list {
    min-height: 360px;
  }

  .result-head {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .candidate-score {
    grid-column: 2 / -1;
  }
}
