:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #dce1e6;
  --line-strong: #c4ccd4;
  --text: #17212b;
  --muted: #667381;
  --primary: #c65319;
  --primary-dark: #8f3710;
  --primary-soft: #fff1e9;
  --success: #24744a;
  --success-soft: #e9f6ee;
  --warning: #9a651a;
  --warning-soft: #fff5dd;
  --danger: #b23636;
  --shadow: 0 8px 24px rgba(23, 33, 43, .07);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 58px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 1440px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 30px;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 116px; font-size: 17px; font-weight: 750; }
.brand-mark {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: var(--primary);
  font-size: 14px;
  font-weight: 800;
}
.view-tabs { display: flex; align-self: stretch; gap: 4px; }
.view-tab {
  position: relative;
  padding: 0 15px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 600;
}
.view-tab:hover { color: var(--text); }
.view-tab.active { color: var(--primary-dark); }
.view-tab.active::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: -1px;
  left: 12px;
  height: 2px;
  background: var(--primary);
}
.service-state { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa4ad; }
.service-state.ok .state-dot { background: #2f9b62; }
.service-state.error .state-dot { background: var(--danger); }

.app-main { max-width: 1440px; margin: 0 auto; padding: 26px 24px 54px; }
.view { display: none; }
.view.active { display: block; }
.page-heading { min-height: 54px; margin-bottom: 20px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading h1 { margin: 0 0 5px; font-size: 25px; line-height: 1.2; }
.page-heading p { margin: 0; color: var(--muted); font-size: 13px; }

.btn {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface);
  font-weight: 600;
}
.btn:hover { border-color: #9aa7b2; background: #fbfcfd; }
.btn.primary { border-color: var(--primary); color: #fff; background: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { border-color: #e2b5b5; color: var(--danger); background: #fff; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 12px; }
.btn:disabled { cursor: not-allowed; opacity: .5; }

.metric-strip {
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric-strip > div { min-height: 74px; padding: 14px 18px; border-right: 1px solid var(--line); }
.metric-strip > div:last-child { border-right: 0; }
.metric-strip span { display: block; color: var(--muted); font-size: 12px; }
.metric-strip strong { display: block; margin-top: 5px; font-size: 23px; }

.questions-layout { display: grid; grid-template-columns: minmax(430px, 1.08fr) minmax(430px, .92fr); gap: 18px; align-items: start; }
.papers-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; }
.settings-layout { display: grid; grid-template-columns: minmax(360px, 430px) minmax(0, 1fr); gap: 18px; align-items: start; }
.list-panel, .detail-panel, .paper-detail, .form-panel, .provider-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.list-panel { padding: 14px; }
.detail-panel, .paper-detail { min-height: 560px; padding: 20px; }
.form-panel, .provider-area { padding: 18px; }

.filter-bar { display: grid; grid-template-columns: minmax(160px, 1fr) 120px 120px auto; gap: 8px; }
.filter-bar input, .filter-bar select, form input[type="text"], form input[type="password"], form input:not([type]) {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  outline: none;
}
.filter-bar input:focus, .filter-bar select:focus, form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(198, 83, 25, .12); }
.list-toolbar { min-height: 44px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.check-label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.check-label input { accent-color: var(--primary); }

.question-list { display: grid; gap: 9px; }
.question-item {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 12px 13px 11px 43px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  cursor: pointer;
}
.question-item:hover { border-color: #aeb8c1; background: #fff; }
.question-item.active { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.question-item > input { position: absolute; top: 15px; left: 14px; accent-color: var(--primary); }
.item-top { position: relative; min-width: 0; display: flex; align-items: center; gap: 8px; margin-bottom: 7px; padding-right: 45px; }
.item-top time { min-width: 0; margin-left: auto; overflow: hidden; color: #8994a0; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.item-delete {
  position: absolute;
  top: -2px;
  right: 0;
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid #e2b5b5;
  border-radius: 5px;
  color: var(--danger);
  background: #fff;
  font-size: 11px;
  line-height: 22px;
}
.item-delete:hover { border-color: var(--danger); background: #fff4f4; }
.badge { display: inline-flex; align-items: center; min-height: 21px; padding: 0 7px; border-radius: 8px; font-size: 10px; font-weight: 700; }
.badge.saved { color: var(--success); background: var(--success-soft); }
.badge.draft { color: var(--warning); background: var(--warning-soft); }
.badge.subject { color: #3f637f; background: #edf4f8; }
.question-item h3 { margin: 0 0 6px; overflow: hidden; color: #202b35; font-size: 14px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.question-item p { margin: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.question-item .knowledge { margin-top: 7px; color: #8a5d2d; font-size: 11px; }
.question-pagination {
  min-height: 32px;
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.question-pagination .btn { min-width: 58px; }
.question-pagination .btn:disabled { opacity: .45; }

.empty-state, .empty-detail { min-height: 160px; display: grid; place-content: center; gap: 7px; color: var(--muted); text-align: center; }
.empty-detail { min-height: 480px; }
.empty-detail strong { color: #3f4a55; font-size: 15px; }
.empty-detail span { font-size: 12px; }

.detail-head { padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.detail-head h2 { margin: 0; font-size: 20px; line-height: 1.45; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.detail-section { padding: 15px 0; border-bottom: 1px solid var(--line); }
.detail-section:last-child { border-bottom: 0; }
.detail-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.detail-section p { margin: 0; line-height: 1.7; }
.detail-section.answer p { color: var(--primary-dark); font-weight: 650; }
.solution-list { margin: 0; padding-left: 20px; line-height: 1.75; }
.solution-list li + li { margin-top: 5px; }
.knowledge-point { display: inline-block; padding: 5px 9px; border-radius: 6px; color: #80501f; background: #fff4e5; }
.practice-result { margin-top: 14px; padding: 14px; border: 1px solid #b9d9c7; border-radius: 7px; background: var(--success-soft); }
.practice-result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.practice-result-head h3 { margin: 0; font-size: 14px; }
.practice-result-head span { color: var(--success); font-size: 11px; }
.practice-result p { margin: 6px 0 0; line-height: 1.6; }
.practice-reveal { margin-top: 10px; }
.practice-answer-content { margin-top: 10px; padding-top: 8px; border-top: 1px solid #b9d9c7; }

.section-title { margin-bottom: 12px; color: #3a4652; font-size: 13px; font-weight: 750; }
.paper-list { display: grid; gap: 8px; }
.paper-item { padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); cursor: pointer; }
.paper-item:hover, .paper-item.active { border-color: var(--primary); background: #fff; }
.paper-item h3 { margin: 0 0 5px; font-size: 14px; }
.paper-item p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.paper-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 16px; border-bottom: 2px solid #323d47; }
.paper-head h2 { margin: 0; font-size: 24px; }
.paper-head p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.paper-item-block { padding: 18px 0; border-bottom: 1px solid var(--line); }
.paper-item-block:last-child { border-bottom: 0; }
.paper-item-block h3 { margin: 0 0 10px; font-size: 15px; line-height: 1.6; }
.paper-answer { margin-top: 12px; padding: 12px; border-radius: 6px; background: var(--surface-soft); line-height: 1.65; }

form label { display: grid; gap: 6px; margin-bottom: 13px; color: #4a5560; font-size: 12px; font-weight: 650; }
.form-checks { display: flex; gap: 18px; margin: 4px 0 16px; }
.form-actions { display: flex; gap: 8px; }
.inline-message { margin-top: 12px; padding: 10px; border-radius: 6px; color: var(--danger); background: #fff0f0; font-size: 12px; line-height: 1.5; }
.inline-message.success { color: var(--success); background: var(--success-soft); }
.provider-list { display: grid; gap: 9px; }
.provider-item { padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
.provider-item.default { border-color: #d3a57e; background: var(--primary-soft); }
.provider-main { display: flex; align-items: flex-start; gap: 12px; }
.provider-main > div:first-child { min-width: 0; flex: 1; }
.provider-main h3 { margin: 0 0 4px; font-size: 14px; }
.provider-main p { margin: 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.provider-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.provider-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.logs-title { margin-top: 24px; }
.log-list { display: grid; }
.log-row { min-height: 38px; display: grid; grid-template-columns: 80px minmax(0, 1fr) 72px 80px; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.log-row strong { overflow: hidden; color: #46515c; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.log-row .status-ok { color: var(--success); }
.log-row .status-error { color: var(--danger); }
.log-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 11px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  max-width: 380px;
  padding: 11px 15px;
  border-radius: 7px;
  color: #fff;
  background: #222d37;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .2);
  line-height: 1.45;
}
.toast.error { background: #8d2f2f; }

@media (max-width: 1000px) {
  .questions-layout, .papers-layout, .settings-layout { grid-template-columns: 1fr; }
  .detail-panel, .paper-detail { min-height: auto; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .metric-strip > div:nth-child(2) { border-right: 0; }
  .metric-strip > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 700px) {
  .header-inner { padding: 0 13px; gap: 6px; }
  .brand { min-width: 44px; }
  .brand > span:last-child { display: none; }
  .view-tabs { flex: 1; justify-content: center; }
  .view-tab { padding: 0 10px; font-size: 13px; }
  .service-state { display: none; }
  .app-main { padding: 18px 12px 40px; }
  .page-heading { align-items: center; }
  .page-heading h1 { font-size: 22px; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar input { grid-column: 1 / -1; }
  .filter-bar .btn { min-height: 36px; }
  .log-row { grid-template-columns: 66px minmax(0, 1fr) 60px; }
  .log-row span:last-child { display: none; }
}

@media print {
  body { background: #fff; }
  .app-header, .page-heading, .papers-layout > .list-panel, .toast { display: none !important; }
  .app-main { max-width: none; margin: 0; padding: 0; }
  #view-papers { display: block !important; }
  .papers-layout { display: block; }
  .paper-detail { min-height: 0; padding: 0; border: 0; box-shadow: none; }
  .paper-detail .btn { display: none; }
  .paper-item-block { break-inside: avoid; }
}
