:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-muted: #f7f8f6;
  --ink: #1c2420;
  --muted: #68716c;
  --line: #dce2de;
  --line-strong: #c5cec8;
  --accent: #087c68;
  --accent-strong: #056453;
  --accent-soft: #e6f4f0;
  --amber: #a76412;
  --amber-soft: #fff2dc;
  --red: #b13e38;
  --red-soft: #fdecea;
  --nav: #17221d;
  --nav-muted: #9eb0a6;
  --shadow: 0 10px 30px rgba(28, 36, 32, .08);
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, "Noto Sans SC", "Microsoft YaHei", sans-serif; font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
svg { width: 18px; height: 18px; stroke-width: 1.8; flex: 0 0 auto; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #edf1ee; }
.login-panel { width: min(410px, 100%); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 34px; border-radius: var(--radius); display: grid; grid-template-columns: 48px 1fr; gap: 18px; }
.login-panel h1 { margin: 2px 0 0; font-size: 25px; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; background: var(--accent); color: white; font-weight: 800; border-radius: 4px; }
.brand-mark.small { width: 36px; height: 36px; font-size: 12px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.login-form { grid-column: 1 / -1; display: grid; gap: 15px; margin-top: 12px; }
label { display: grid; gap: 7px; color: #37403b; font-size: 13px; font-weight: 600; }
input, select, textarea { width: 100%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 4px; padding: 10px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8, 124, 104, .11); }
textarea { min-height: 104px; resize: vertical; line-height: 1.55; }
.form-error { min-height: 18px; margin: 0; color: var(--red); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--nav); color: white; display: flex; flex-direction: column; padding: 18px 12px 14px; z-index: 20; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 15px; }
.sidebar-brand span { color: var(--nav-muted); font-size: 11px; margin-top: 2px; }
.main-nav { display: grid; gap: 3px; }
.main-nav button { height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border: 0; background: transparent; color: var(--nav-muted); border-radius: 4px; text-align: left; }
.main-nav button:hover { color: white; background: rgba(255,255,255,.06); }
.main-nav button.active { color: white; background: #285344; }
.sidebar-footer { margin-top: auto; padding: 14px 7px 0; border-top: 1px solid rgba(255,255,255,.11); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-block { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-block > span { width: 30px; height: 30px; display: grid; place-items: center; background: #d8e8df; color: var(--nav); border-radius: 50%; font-size: 11px; font-weight: 800; }
.user-block strong, .user-block small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 105px; }
.user-block small { color: var(--nav-muted); font-size: 10px; margin-top: 2px; }
.sidebar .icon-button { color: var(--nav-muted); }

.workspace { min-width: 0; }
.topbar { min-height: 76px; display: flex; align-items: center; gap: 16px; justify-content: space-between; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 3px 0 0; font-size: 20px; line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.page-content { width: 100%; padding: 24px 28px 42px; }

.button { min-height: 38px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 4px; padding: 8px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 650; }
.button:hover { background: var(--surface-muted); }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-strong); }
.button.danger { border-color: #e1aaa6; color: var(--red); background: var(--red-soft); }
.button.ghost { background: transparent; border-color: transparent; }
.button.small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.button.full { width: 100%; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 4px; padding: 0; }
.icon-button:hover { border-color: var(--line); background: var(--surface-muted); color: var(--ink); }
.status-pill { min-height: 30px; display: inline-flex; align-items: center; gap: 7px; padding: 4px 9px; border: 1px solid var(--line); background: var(--surface-muted); border-radius: 99px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-pill > span { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.status-pill.ok > span { background: var(--accent); }
.status-pill.error > span { background: var(--red); }
.inline-notice { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid #c8e6dd; background: var(--accent-soft); color: var(--accent-strong); border-radius: 4px; }
.inline-notice.error { border-color: #e7b9b5; background: var(--red-soft); color: #7f302c; }
.inline-notice > div { min-width: 0; flex: 1; }
.inline-notice strong { display: block; line-height: 1.4; }
.inline-notice p { margin: 4px 0 0; color: inherit; line-height: 1.45; }
.inline-notice .button { flex: 0 0 auto; }

.page-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-header h2 { margin: 0; font-size: 18px; }
.page-header p { margin: 5px 0 0; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.metric { min-height: 112px; padding: 18px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { display: block; font-size: 27px; margin-top: 10px; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 6px; color: var(--muted); }
.metric.good strong { color: var(--accent-strong); }
.metric.warn strong { color: var(--amber); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 18px; margin-top: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.panel-header { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-header h3 { margin: 0; font-size: 14px; }
.panel-body { padding: 16px; }
.panel-body.flush { padding: 0; }
.empty-state { min-height: 160px; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 30px; }

.toolbar { display: grid; grid-template-columns: minmax(230px, 1fr) 160px 160px auto; gap: 9px; margin-bottom: 14px; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 11px; top: 10px; color: var(--muted); }
.search-field input { padding-left: 36px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { position: sticky; top: 0; z-index: 1; background: #f1f4f2; color: #52605a; text-align: left; font-size: 11px; text-transform: uppercase; font-weight: 750; padding: 10px 12px; border-bottom: 1px solid var(--line-strong); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.45; }
tbody tr:hover { background: #f7faf8; }
.table-title { font-weight: 650; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.table-subtitle { color: var(--muted); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-flex; align-items: center; min-height: 23px; padding: 2px 7px; background: #eef2ef; border: 1px solid var(--line); border-radius: 3px; color: #4f5a54; font-size: 11px; white-space: nowrap; }
.tag.ip2free { background: #e7f3f8; color: #246079; border-color: #cae3ed; }
.tag.lycheeip { background: var(--accent-soft); color: var(--accent-strong); border-color: #c8e6dd; }
.tag.tkspmall { background: var(--amber-soft); color: #84500f; border-color: #efd6aa; }
.tag.canonical, .tag.ops_console { background: #e9f5ed; color: #26633a; border-color: #cce3d3; }
.pagination { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); }

.split-view { display: grid; grid-template-columns: minmax(290px, .8fr) minmax(420px, 1.2fr); min-height: 590px; }
.split-list { border-right: 1px solid var(--line); overflow: auto; max-height: calc(100vh - 190px); }
.list-item { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); text-align: left; padding: 13px 15px; color: var(--ink); }
.list-item:hover, .list-item.active { background: #edf6f2; }
.list-item strong { display: block; margin-bottom: 5px; }
.list-item small { color: var(--muted); }
.conversation-detail { min-width: 0; padding: 18px; overflow: auto; max-height: calc(100vh - 190px); background: #f8faf8; }
.message { max-width: 78%; margin-bottom: 13px; padding: 10px 12px; background: white; border: 1px solid var(--line); border-radius: 5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.message.assistant { margin-left: auto; background: #e8f4ef; border-color: #cbe3da; }
.message-meta { margin-top: 5px; color: var(--muted); font-size: 10px; }

.retrieval-layout { display: grid; grid-template-columns: minmax(320px, .55fr) minmax(480px, 1.45fr); gap: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; }
.switch { width: 42px; height: 24px; position: relative; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #b9c1bc; border-radius: 99px; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.evidence-list { display: grid; gap: 10px; }
.evidence { border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--surface); padding: 13px 14px; border-radius: 3px; }
.evidence-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.evidence h4 { margin: 0; font-size: 14px; }
.evidence p { margin: 9px 0 0; color: #3f4944; line-height: 1.55; white-space: pre-wrap; }
.rank-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.definition-list { display: grid; grid-template-columns: minmax(110px, .45fr) minmax(0, 1fr); gap: 10px 16px; margin: 0; }
.definition-list dt { color: var(--muted); }
.definition-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.pipeline { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.pipeline span { padding: 5px 8px; background: #edf2ef; border: 1px solid var(--line); border-radius: 3px; font-size: 11px; }
.pipeline svg { width: 13px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(14, 21, 17, .48); display: grid; place-items: center; padding: 20px; }
.modal { width: min(850px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: var(--radius); box-shadow: 0 24px 70px rgba(0,0,0,.22); }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; position: sticky; bottom: 0; background: var(--surface); }
.modal-body { padding: 18px; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.editor-grid .wide { grid-column: 1 / -1; }

.job-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 110px; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.progress-line { height: 5px; background: #e4e9e6; overflow: hidden; border-radius: 99px; }
.progress-line span { display: block; height: 100%; background: var(--accent); }
.code-output { margin: 0; min-height: 220px; max-height: 520px; overflow: auto; background: #17211c; color: #dfe9e3; padding: 15px; border-radius: 4px; white-space: pre-wrap; word-break: break-word; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.55; }
.upload-row { display: flex; gap: 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.upload-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row small { margin-left: auto; color: var(--muted); white-space: nowrap; }

.toast-region { position: fixed; top: 16px; right: 16px; z-index: 120; display: grid; gap: 8px; }
.toast { width: min(360px, calc(100vw - 32px)); padding: 11px 13px; color: white; background: #26332c; border-radius: 4px; box-shadow: var(--shadow); }
.toast.error { background: #8e302c; }
.skeleton { min-height: 18px; background: linear-gradient(90deg, #edf0ee 25%, #f7f8f7 50%, #edf0ee 75%); background-size: 200% 100%; animation: pulse 1.2s infinite; border-radius: 3px; }
@keyframes pulse { to { background-position: -200% 0; } }
.mobile-only { display: none; }

@media (max-width: 1050px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dashboard-grid, .retrieval-layout { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: minmax(220px, 1fr) 150px 150px; }
  .toolbar .button { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: -240px; width: 224px; transition: left .18s; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-grid; }
  .topbar { padding: 12px 14px; min-height: 68px; }
  .topbar-actions .status-pill { display: none; }
  .page-content { padding: 16px 12px 30px; }
  .page-header { align-items: start; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 96px; padding: 14px; }
  .metric strong { font-size: 22px; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search-field, .toolbar .button { grid-column: 1 / -1; }
  .split-view { grid-template-columns: 1fr; }
  .split-list { max-height: 270px; border-right: 0; border-bottom: 1px solid var(--line); }
  .conversation-detail { max-height: none; min-height: 420px; }
  .form-grid, .editor-grid { grid-template-columns: 1fr; }
  .form-grid .wide, .editor-grid .wide { grid-column: auto; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { max-height: 94vh; border-radius: 6px 6px 0 0; }
  .message { max-width: 92%; }
  .job-row { grid-template-columns: 90px 1fr; }
  .job-row > :last-child { grid-column: 1 / -1; }
  th:nth-child(3), td:nth-child(3) { display: none; }
}
