:root {
  color-scheme: light;
  --ink: #17233b;
  --muted: #6b7891;
  --line: #dce4ef;
  --panel: rgba(255, 255, 255, 0.94);
  --blue: #1c63d5;
  --blue-dark: #124aa7;
  --blue-soft: #eaf2ff;
  --green: #1b8f63;
  --green-soft: #e9f8f1;
  --red: #c4474d;
  --red-soft: #fff0f0;
  --amber: #b77819;
  --amber-soft: #fff7e7;
  --shadow: 0 16px 44px rgba(31, 56, 98, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1080px;
  background:
    radial-gradient(circle at 10% 2%, rgba(63, 130, 234, 0.16), transparent 30rem),
    linear-gradient(180deg, #f5f8fd 0, #f8fafc 36rem, #f3f6fa 100%);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1500px, calc(100% - 64px));
  margin: 0 auto;
  padding: 42px 0 64px;
}

.hero,
.panel-heading,
.section-heading,
.action-row,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.hero {
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow,
.step-label {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.hero h1 {
  margin: 8px 0 10px;
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: -0.035em;
}

.hero p {
  max-width: 810px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.hero-badge,
.mcp-status,
.mode-state {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.hero-badge {
  gap: 9px;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(27, 143, 99, 0.2);
  background: rgba(233, 248, 241, 0.82);
  color: #156f4e;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid #d6e0ed;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.86);
  color: #55657d;
  font-size: 11px;
}

.user-menu a,
.link-button,
.back-link {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  text-decoration: none;
}

.user-menu a:hover,
.link-button:hover,
.back-link:hover {
  text-decoration: underline;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25a777;
  box-shadow: 0 0 0 5px rgba(37, 167, 119, 0.12);
}

.mode-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 15px;
  min-height: 88px;
  padding: 17px 20px;
  border: 1px solid #d7e1ef;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 7px 22px rgba(35, 59, 97, 0.04);
  cursor: pointer;
  text-align: left;
  transition: 160ms ease;
}

.mode-card:hover {
  border-color: #a9c5ee;
  transform: translateY(-1px);
}

.mode-card.active {
  border-color: #86afe9;
  background: white;
  box-shadow:
    0 0 0 2px rgba(28, 99, 213, 0.08),
    0 12px 30px rgba(28, 99, 213, 0.1);
}

.mode-number,
.file-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 14px;
  font-weight: 850;
}

.mode-copy strong,
.mode-copy small {
  display: block;
}

.mode-copy strong {
  margin-bottom: 4px;
  font-size: 16px;
}

.mode-copy small {
  color: var(--muted);
  font-size: 12px;
}

.mode-state,
.mcp-status {
  padding: 7px 10px;
}

.mode-state.available,
.mcp-status.connected {
  background: var(--green-soft);
  color: #147552;
}

.mode-state.pending,
.mcp-status.pending {
  background: var(--amber-soft);
  color: #946014;
}

.panel {
  border: 1px solid #d4dfed;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.upload-panel,
.mcp-panel {
  padding: 30px;
}

.panel-heading {
  align-items: flex-start;
  margin-bottom: 24px;
}

.panel-heading h2,
.section-heading h2 {
  margin: 7px 0 0;
  font-size: 25px;
  letter-spacing: -0.025em;
}

.heading-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.upload-grid {
  display: grid;
  gap: 16px;
}

.file-upload-grid {
  grid-template-columns: 1fr 1fr 0.82fr;
}

.file-card,
.context-card {
  min-height: 144px;
  border: 1px solid #d9e3f1;
  border-radius: 16px;
  background: #fbfcfe;
}

.file-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 12px 14px;
  padding: 20px;
  cursor: pointer;
  transition: 160ms ease;
}

.file-card:hover {
  border-color: #99bce9;
  background: #f8fbff;
}

.file-card strong,
.file-card small {
  display: block;
}

.file-card strong {
  font-size: 14px;
}

em {
  color: var(--red);
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
}

.file-card small,
.context-card small,
.control-field small {
  margin-top: 5px;
  color: #7f8ba0;
  font-size: 11px;
  line-height: 1.5;
}

.file-name {
  grid-column: 2;
  overflow: hidden;
  color: var(--blue);
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card input[type="file"] {
  display: none;
}

.context-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
}

.context-card label span,
.control-field > span {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 750;
}

input,
select {
  width: 100%;
  border: 1px solid #cfdbea;
  border-radius: 11px;
  background: white;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus {
  border-color: #78a5e4;
  box-shadow: 0 0 0 3px rgba(28, 99, 213, 0.09);
}

input:disabled,
select:disabled {
  cursor: not-allowed;
  background: #f3f5f8;
  color: #8994a5;
}

.context-card input {
  padding: 11px 12px;
}

.action-row {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.rule-note {
  color: #63738d;
  font-size: 13px;
}

code {
  padding: 2px 6px;
  border-radius: 5px;
  background: #eff3f8;
  color: #31567f;
}

.button {
  min-height: 42px;
  padding: 10px 18px;
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.button.primary {
  min-width: 150px;
  background: linear-gradient(135deg, #246bd4, #1654b8);
  box-shadow: 0 9px 21px rgba(28, 99, 213, 0.22);
  color: white;
}

.button.secondary {
  border: 1px solid #b8cceb;
  background: #f7faff;
  color: #24548e;
}

.button.ghost {
  border: 1px solid #b9cce8;
  background: white;
  color: #31567f;
}

.button.danger-outline {
  border: 1px solid #e3a6aa;
  background: #fff7f7;
  color: #a3333a;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  box-shadow: none;
}

.message {
  margin-top: 16px;
  padding: 13px 15px;
  border-radius: 11px;
  font-size: 12px;
}

.message.error {
  background: var(--red-soft);
  color: #9d3036;
}

.message.loading {
  background: #eef5ff;
  color: #315b8c;
}

.mcp-controls {
  display: grid;
  grid-template-columns: 1.35fr 1fr 0.85fr auto;
  align-items: end;
  gap: 14px;
  padding: 20px;
  border: 1px solid #dbe5f2;
  border-radius: 16px;
  background: #f8fafd;
}

.control-field select {
  height: 44px;
  padding: 0 12px;
}

.audit-button {
  height: 44px;
  margin-bottom: 21px;
}

.permission-notice {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin-top: 16px;
  padding: 15px 17px;
  border: 1px solid #ead7ae;
  border-radius: 13px;
  background: var(--amber-soft);
  color: #78541a;
}

.notice-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #edc66e;
  color: #63450f;
  font-size: 12px;
  font-weight: 900;
}

.permission-notice strong {
  font-size: 13px;
}

.permission-notice p {
  margin: 5px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

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

.logic-grid article {
  display: flex;
  gap: 14px;
  padding: 17px;
  border: 1px solid #dfe7f1;
  border-radius: 14px;
  background: white;
}

.logic-index {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 36px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 850;
}

.logic-index.danger {
  background: var(--red-soft);
  color: var(--red);
}

.logic-index.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.logic-grid strong {
  font-size: 13px;
}

.logic-grid p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.results {
  margin-top: 28px;
}

.section-heading {
  align-items: flex-end;
}

.source-meta {
  max-width: 55%;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 18px 0;
}

.kpi-grid.five {
  grid-template-columns: repeat(5, 1fr);
}

.kpi-card {
  min-height: 126px;
  padding: 19px;
  border: 1px solid #dce5f1;
  border-radius: 15px;
  background: white;
  box-shadow: 0 9px 26px rgba(30, 55, 96, 0.06);
}

.kpi-card > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin: 11px 0 6px;
  font-size: 29px;
  letter-spacing: -0.04em;
}

.kpi-card small {
  color: #8a96aa;
  font-size: 10px;
}

.kpi-card.success {
  border-top: 3px solid var(--green);
}

.kpi-card.success strong {
  color: var(--green);
}

.kpi-card.danger {
  border-top: 3px solid var(--red);
}

.kpi-card.danger strong {
  color: var(--red);
}

.kpi-card.warning {
  border-top: 3px solid var(--amber);
}

.kpi-card.warning strong {
  color: var(--amber);
}

.kpi-card.accent {
  border-top: 3px solid var(--blue);
}

.kpi-card.accent strong {
  color: var(--blue);
}

.progress-track {
  height: 6px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf6;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3f86ec, #1b8f63);
  transition: width 400ms ease;
}

.table-panel {
  overflow: hidden;
}

.table-toolbar {
  padding: 17px 19px;
  border-bottom: 1px solid var(--line);
}

.filter-group,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-group select {
  width: 190px;
  padding: 10px 34px 10px 11px;
}

.filter-group input {
  width: 340px;
  padding: 10px 12px;
}

.result-count {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  height: 600px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 13px 15px;
  border-bottom: 1px solid #e8edf4;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  position: sticky;
  z-index: 1;
  top: 0;
  background: #f6f8fb;
  color: #5f6d85;
  font-size: 11px;
  font-weight: 800;
}

td {
  color: #334058;
  font-size: 12px;
}

.file-results-table th:nth-child(1) { width: 17%; }
.file-results-table th:nth-child(2) { width: 14%; }
.file-results-table th:nth-child(3) { width: 11%; }
.file-results-table th:nth-child(4) { width: 20%; }
.file-results-table th:nth-child(5) { width: 27%; }
.file-results-table th:nth-child(6) { width: 11%; }

.mcp-results-table th:nth-child(1) { width: 13%; }
.mcp-results-table th:nth-child(2) { width: 12%; }
.mcp-results-table th:nth-child(3) { width: 21%; }
.mcp-results-table th:nth-child(4) { width: 9%; }
.mcp-results-table th:nth-child(5) { width: 10%; }
.mcp-results-table th:nth-child(6) { width: 9%; }
.mcp-results-table th:nth-child(7) { width: 14%; }
.mcp-results-table th:nth-child(8) { width: 14%; }

tbody tr:hover {
  background: #f9fbff;
}

.status-pill {
  display: inline-flex;
  min-width: 64px;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.status-pill.matched {
  background: var(--green-soft);
  color: #177452;
}

.status-pill.unmatched {
  background: var(--red-soft);
  color: #a73a40;
}

.status-pill.no-request {
  background: var(--amber-soft);
  color: #8a5b13;
}

.empty-cell {
  color: #a6afbe;
}

.empty-state {
  padding: 70px 20px;
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 14px 19px;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
}

.page-button {
  padding: 7px 11px;
  border: 1px solid #cbd7e7;
  border-radius: 8px;
  background: white;
  color: #415674;
  cursor: pointer;
}

.page-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.hidden {
  display: none !important;
}

.auth-body {
  min-width: 0;
  min-height: 100vh;
}

.auth-shell {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  align-items: center;
  gap: 80px;
  width: min(1040px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 48px 0;
}

.auth-brand h1 {
  max-width: 540px;
  margin: 12px 0 16px;
  font-size: clamp(38px, 5vw, 62px);
  line-height: 1.08;
  letter-spacing: -0.05em;
}

.auth-brand > p {
  color: var(--muted);
  font-size: 17px;
}

.security-points {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.security-points span {
  padding: 8px 12px;
  border: 1px solid #cfe0f5;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: #315b8c;
  font-size: 12px;
  font-weight: 750;
}

.auth-card {
  padding: 36px;
  border: 1px solid #d4dfed;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 70px rgba(29, 55, 97, 0.15);
}

.lock-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 22px;
  border-radius: 13px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 20px;
  font-weight: 900;
}

.auth-card h2 {
  margin: 7px 0 8px;
  font-size: 28px;
}

.auth-card > p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.auth-card form {
  display: grid;
  gap: 17px;
}

.auth-card label span,
.admin-form label span {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
}

.auth-card input {
  height: 47px;
  padding: 0 13px;
}

.auth-submit {
  width: 100%;
  margin-top: 3px;
}

.auth-help {
  display: block;
  margin-top: 17px;
  color: #8a96aa;
  font-size: 10px;
  line-height: 1.6;
}

.admin-shell {
  max-width: 1380px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 24px;
}

.admin-header .eyebrow {
  margin-top: 24px;
}

.admin-header h1 {
  margin: 8px 0;
  font-size: 36px;
  letter-spacing: -0.04em;
}

.admin-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-layout {
  display: grid;
  gap: 18px;
}

.admin-create-panel,
.code-reveal,
.admin-table-panel {
  padding: 24px;
}

.admin-create-panel h2,
.code-reveal h2,
.admin-section-heading h2 {
  margin: 6px 0 18px;
  font-size: 22px;
}

.admin-form {
  display: grid;
  grid-template-columns: 1fr 1fr 0.7fr auto;
  align-items: end;
  gap: 13px;
}

.admin-form input,
.admin-form select {
  height: 43px;
  padding: 0 12px;
}

.admin-tip {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.code-reveal {
  border-color: #a8c5ec;
  background: linear-gradient(135deg, #f4f8ff, white);
}

.code-reveal h2 {
  margin-bottom: 6px;
}

.code-reveal p {
  margin: 0 0 15px;
  color: var(--muted);
  font-size: 12px;
}

.code-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.code-box code {
  flex: 1;
  padding: 14px 16px;
  border: 1px dashed #8eb1e3;
  border-radius: 11px;
  background: white;
  color: #164d97;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.code-reveal > small {
  display: block;
  margin-bottom: 12px;
  color: #7a879c;
  font-size: 10px;
}

.admin-section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.admin-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-table-wrap {
  height: auto;
  max-height: 520px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.audit-table-wrap {
  height: 390px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.admin-users-table th:nth-child(1) { width: 15%; }
.admin-users-table th:nth-child(2) { width: 18%; }
.admin-users-table th:nth-child(3) { width: 10%; }
.admin-users-table th:nth-child(4) { width: 10%; }
.admin-users-table th:nth-child(5) { width: 20%; }
.admin-users-table th:nth-child(6) { width: 27%; }

.audit-table th:nth-child(1) { width: 18%; }
.audit-table th:nth-child(2) { width: 13%; }
.audit-table th:nth-child(3) { width: 20%; }
.audit-table th:nth-child(4) { width: 15%; }
.audit-table th:nth-child(5) { width: 34%; }

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

.role-pill.admin {
  background: var(--blue-soft);
  color: var(--blue);
}

.role-pill.user {
  background: #f0f2f6;
  color: #66748a;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-actions button {
  padding: 5px 8px;
  border: 1px solid #cbd8e8;
  border-radius: 7px;
  background: white;
  color: #315b8c;
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
}

.row-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

@media (max-width: 1250px) {
  .page-shell {
    width: calc(100% - 40px);
  }

  .file-upload-grid {
    grid-template-columns: 1fr 1fr;
  }

  .context-card {
    grid-column: span 2;
    min-height: auto;
  }

  .mcp-controls {
    grid-template-columns: 1fr 1fr;
  }

  .audit-button {
    margin: 0;
  }

  .kpi-grid.five {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 760px) {
  .auth-shell {
    grid-template-columns: 1fr;
    gap: 28px;
    width: min(520px, calc(100% - 28px));
    padding: 28px 0;
  }

  .auth-brand h1 {
    font-size: 38px;
  }

  .auth-brand > p,
  .security-points {
    display: none;
  }

  .auth-card {
    padding: 26px;
  }
}
