:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #1f5eff;
  --brand-soft: #eef3ff;
  --ok: #12b76a;
  --warn: #f79009;
  --bad: #f04438;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(circle at 20% 0%, #eef3ff 0, transparent 38%), var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--brand); color: #fff;
  font-weight: 800; letter-spacing: 0.5px;
}

.brand strong { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }

.top-actions { display: flex; align-items: center; gap: 18px; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); font-size: 13px;
}
.status i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); display: inline-block;
}
.status.ok i { background: var(--ok); }
.status.degraded i { background: var(--warn); }
.status.bad i { background: var(--bad); }

.mode { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.mode select {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 9px; padding: 6px 10px;
}

.page { max-width: 1080px; margin: 0 auto; padding: 36px 24px 80px; }

.hero h1 { font-size: clamp(24px, 3.4vw, 36px); margin: 0 0 8px; letter-spacing: -0.5px; }
.sub { color: var(--muted); margin: 0 0 22px; }

.search-box {
  display: flex; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px; border-radius: 16px; box-shadow: var(--shadow);
}
.search-box input {
  flex: 1; border: 0; outline: 0; padding: 12px 14px; background: transparent;
  font-size: 16px;
}
.search-box button {
  border: 0; border-radius: 11px; background: var(--brand); color: #fff;
  padding: 12px 24px; font-weight: 650; cursor: pointer;
}
.search-box button:disabled { opacity: 0.6; cursor: wait; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; }
.chips button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.chips button:hover { color: var(--brand); border-color: #c7d7fe; background: var(--brand-soft); }

.filters { margin: 14px 0 4px; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 14px; }
.filters summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.filter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.filter-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.filter-grid input {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); background: #fff;
}

.results { margin-top: 30px; }
.results-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-bottom: 12px; }

.result-list { display: grid; gap: 12px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; cursor: pointer; transition: 0.15s ease;
}
.card:hover { border-color: #c7d7fe; box-shadow: 0 8px 24px rgba(31, 94, 255, 0.08); transform: translateY(-1px); }

.card-top { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; }
.card h3 { margin: 0; font-size: 17px; }
.score { color: var(--brand); font-size: 12px; background: var(--brand-soft); border-radius: 999px; padding: 3px 9px; white-space: nowrap; }

.meta { color: var(--muted); font-size: 12.5px; margin: 7px 0 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.meta b { color: var(--ink); font-weight: 600; }

.snippet { margin: 0; color: #344054; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.reason { margin-top: 10px; color: var(--muted); font-size: 12px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(255,255,255,0.6); }
.error { color: var(--bad); border: 1px solid #fecdca; background: #fffbfa; padding: 18px; border-radius: var(--radius); }

.drawer {
  position: fixed; top: 0; right: 0; width: min(560px, 92vw); height: 100%;
  background: #fff; border-left: 1px solid var(--line); box-shadow: -20px 0 50px rgba(16,24,40,0.12);
  transform: translateX(102%); transition: transform 0.22s ease; z-index: 30; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 22px 24px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; }
.drawer-head small { color: var(--muted); font-size: 12px; }
.drawer-head h2 { margin: 4px 0 0; font-size: 20px; }
.drawer-body { padding: 20px 24px 40px; overflow: auto; }

.icon-btn { border: 0; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; border-radius: 999px; padding: 3px 9px; }
.badge.ok { color: #027a48; background: #ecfdf3; }
.badge.warn { color: #b54708; background: #fffaeb; }

.section { margin: 18px 0; }
.section h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.clause {
  background: #f9fafb; border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; white-space: pre-wrap; color: #344054; font-size: 14px;
}
.context { color: var(--muted); font-size: 13px; white-space: pre-wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.actions a, .actions button {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 9px; padding: 8px 14px; text-decoration: none; cursor: pointer;
}
.actions a.primary { background: var(--brand); border-color: var(--brand); color: #fff; }

.overlay { position: fixed; inset: 0; background: rgba(16,24,40,0.28); z-index: 20; }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .page { padding: 24px 16px 60px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-box { flex-direction: column; }
  .search-box button { width: 100%; }
}


/* Admin */
.nav-link { color: var(--muted); text-decoration: none; font-size: 13px; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; }
.nav-link:hover { color: var(--brand); border-color: #c7d7fe; }

.admin-page { max-width: 1180px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.admin-head h1 { margin: 0 0 4px; font-size: 26px; }

.ghost-btn, .primary-btn { border-radius: 9px; padding: 8px 14px; cursor: pointer; border: 1px solid var(--line); background: #fff; }
.primary-btn { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 650; }
.primary-btn:disabled { opacity: 0.6; cursor: wait; }

.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.stat-card small { color: var(--muted); font-size: 12px; }
.stat-card strong { font-size: 22px; letter-spacing: -0.3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-card span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin: 14px 0; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.panel-head h2 { margin: 0 0 2px; font-size: 17px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 12.5px; }
.panel-actions { display: flex; gap: 8px; align-items: center; }
.panel-actions select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 9px 10px; border-bottom: 1px solid #f1f3f5; vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; color: #475467; }
.sub-cell { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.state { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: #f2f4f7; color: #475467; }
.state.ok { background: #ecfdf3; color: #027a48; }
.state.bad { background: #fef3f2; color: #b42318; }
.state.run { background: #eff8ff; color: #175cd3; }
.state.idle { background: #fffaeb; color: #b54708; }

.progress-wrap { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; }
.progress-wrap[hidden] { display: none; }
.data-table td.nowrap { white-space: nowrap; }
.progress { flex: 1; height: 8px; background: #eaecf0; border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--brand); transition: width 0.3s ease; }
#progress-text { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty.small { padding: 18px; font-size: 13px; }

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-head { flex-direction: column; }
}


/* Upload & file management */
.dropzone {
  border: 1px dashed #c7d7fe; background: #f8faff; color: var(--muted);
  border-radius: 12px; padding: 22px; text-align: center; font-size: 13px;
  cursor: pointer; transition: 0.15s ease;
}
.dropzone.drag { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.upload-list { display: grid; gap: 6px; margin-top: 10px; }
.upload-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px;
  align-items: center; font-size: 12.5px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.upload-row small { color: var(--muted); }
.upload-state { color: var(--muted); }
.upload-state.ok { color: #027a48; }
.upload-state.bad { color: #b42318; }
.link-btn { border: 0; background: transparent; color: var(--brand); cursor: pointer; padding: 0; font-size: 12.5px; }
.link-btn:hover { text-decoration: underline; }


/* Admin auth gate */
.auth-gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(16, 24, 40, 0.66); backdrop-filter: blur(8px);
}
.auth-card {
  width: min(420px, 92vw); background: #fff; border-radius: 18px;
  padding: 30px; box-shadow: 0 24px 70px rgba(16,24,40,0.25);
  display: flex; flex-direction: column; gap: 10px;
}
.auth-card .brand-mark { margin-bottom: 4px; }
.auth-card h2 { margin: 4px 0 0; font-size: 22px; }
.auth-card p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-card code { background: #f2f4f7; padding: 1px 5px; border-radius: 4px; }
.auth-card input {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px;
  margin: 8px 0 2px; font-size: 14px;
}
.auth-card .primary-btn { width: 100%; padding: 11px; }
.auth-card a { color: var(--muted); font-size: 12px; text-decoration: none; margin-top: 6px; }
.auth-error { color: var(--bad) !important; min-height: 18px; font-size: 12px !important; }

.user-chip { font-size: 12px; color: #475467; background: #f2f4f7; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }


/* Parsed natural-language filters */
.parsed { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 0 0 12px; }
.parsed[hidden] { display: none; }
.parsed-label { font-size: 12px; color: var(--muted); }
.parsed-chip {
  font-size: 12px; color: var(--brand); background: var(--brand-soft);
  border-radius: 999px; padding: 4px 9px; white-space: nowrap;
}


/* Contract list in evidence drawer */
.contract-list { display: grid; gap: 8px; }
.contract-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
}
.contract-row .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.contract-ext { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }


/* Responsive H5 / mobile */
@media (max-width: 760px) {
  .topbar {
    padding: 10px 14px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .brand { flex: 1 1 100%; gap: 10px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
  .brand strong { font-size: 15px; }
  .brand small { display: none; }

  .top-actions {
    width: 100%;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
  }
  .status { font-size: 12px; white-space: nowrap; }
  .user-chip {
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 4px 8px;
  }
  .nav-link { padding: 6px 9px; font-size: 12px; }
  .mode { margin-left: auto; gap: 4px; font-size: 12px; white-space: nowrap; }
  .mode-label { display: none; }
  .mode select { padding: 6px 8px; }

  .page { padding: 22px 14px 56px; }
  .hero h1 { font-size: clamp(21px, 6vw, 28px); line-height: 1.32; }
  .sub { font-size: 13px; margin-bottom: 16px; }
  .search-box { padding: 6px; border-radius: 14px; }
  .search-box input { padding: 10px 8px; }
  .search-box button { padding: 12px; border-radius: 10px; }
  .chips { gap: 6px; margin-top: 12px; }
  .chips button { padding: 7px 10px; font-size: 12px; }
  .filters { padding: 10px 12px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .results { margin-top: 22px; }
  .results-head { font-size: 12px; }
  .card { padding: 15px 14px; border-radius: 12px; }
  .card h3 { font-size: 16px; line-height: 1.45; }
  .meta { gap: 4px 10px; font-size: 12px; }
  .snippet { font-size: 14px; -webkit-line-clamp: 5; }

  .drawer { width: 100%; border-left: 0; }
  .drawer-head { padding: 16px; }
  .drawer-body { padding: 16px 16px 32px; }
  .actions { gap: 8px; }
  .actions a, .actions button {
    flex: 1 1 auto;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .admin-page { padding-left: 14px; padding-right: 14px; }
  .admin-head h1 { font-size: 22px; }
  .stat-grid { gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card strong { font-size: 18px; }
  .panel { padding: 14px; border-radius: 12px; }
  .panel-head { flex-direction: column; align-items: stretch; gap: 8px; }
  .panel-actions { width: 100%; flex-wrap: wrap; }
  .panel-actions .ghost-btn, .panel-actions .primary-btn { flex: 1 1 auto; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .admin-page .data-table { min-width: 720px; font-size: 12px; }
  .data-table th, .data-table td { padding: 8px; }
  .data-table .nowrap { white-space: nowrap; }
  .nav-link { white-space: nowrap; flex-shrink: 0; }
  .user-chip { flex-shrink: 0; }
  .upload-row { grid-template-columns: 1fr auto; }
}

@media (max-width: 480px) {
  
  .user-chip { max-width: 96px; }
  .filter-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-head h2 { font-size: 16px; }
  .dropzone { padding: 18px 12px; }
  .drawer-head h2 { font-size: 18px; }
}
