:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf5;
  --text-muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 32px; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px;
}
.brand h1 { font-size: 18px; }
.brand p { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-btn {
  background: transparent; border: none; color: var(--text-muted);
  text-align: left; padding: 12px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; transition: .15s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; }

.sidebar-footer { padding-top: 16px; border-top: 1px solid var(--border); }
.status-dot { font-size: 12px; color: var(--text-muted); }
.status-dot::before {
  content: ""; display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 6px; background: var(--text-muted);
}
.status-dot.online::before { background: var(--success); }
.status-dot.offline::before { background: var(--warning); }

.main { flex: 1; padding: 28px 32px; overflow-y: auto; }
.tab { display: none; }
.tab.active { display: block; }

.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-header h2 { font-size: 22px; margin-bottom: 4px; }
.page-header p { color: var(--text-muted); font-size: 13px; }
.actions { display: flex; align-items: center; gap: 12px; }

.btn {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12px; }

.checkbox-label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

.card-list { display: flex; flex-direction: column; gap: 12px; }
.tender-card, .ref-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  transition: .15s;
}
.tender-card:hover { border-color: var(--primary); }
.tender-card .title { font-size: 15px; font-weight: 600; margin-bottom: 8px; line-height: 1.5; }
.tender-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  background: var(--surface2); color: var(--text-muted);
}
.tag.matched { background: rgba(16,185,129,.15); color: var(--success); }
.tag.score { background: rgba(59,130,246,.15); color: var(--primary); }
.tender-actions { display: flex; gap: 8px; margin-top: 10px; }

.editor-layout {
  display: grid; grid-template-columns: 220px 260px 1fr;
  gap: 16px; height: calc(100vh - 160px); min-height: 500px;
}
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
}
.panel h3 {
  padding: 14px 16px; font-size: 13px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .5px;
}
.project-list, .section-list { overflow-y: auto; flex: 1; padding: 8px; }
.project-item, .section-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 13px; margin-bottom: 4px; border: 1px solid transparent;
}
.project-item:hover, .section-item:hover { background: var(--surface2); }
.project-item.active, .section-item.active {
  background: rgba(59,130,246,.12); border-color: var(--primary);
}
.section-item { display: flex; justify-content: space-between; align-items: center; }
.section-item .lvl-2 { padding-left: 12px; font-size: 12px; }
.section-item .lvl-3 { padding-left: 24px; font-size: 12px; }
.badge {
  font-size: 10px; padding: 1px 6px; border-radius: 3px;
  background: var(--surface2); color: var(--text-muted);
}
.badge.done { background: rgba(16,185,129,.2); color: var(--success); }

.right-panel { display: flex; flex-direction: column; }
.editor-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 12px; flex-wrap: wrap;
}
.section-title { font-weight: 600; font-size: 14px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#editor {
  flex: 1; background: var(--bg); color: var(--text); border: none;
  padding: 20px; font-size: 14px; line-height: 1.8; resize: none;
  font-family: inherit; outline: none;
}
#editor:disabled { opacity: .5; }

.quill-toolbar-wrap {
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  background: var(--bg);
}
.quill-toolbar-wrap .ql-toolbar {
  border: none !important;
  background: transparent;
}
.quill-toolbar-wrap .ql-stroke { stroke: var(--text-muted) !important; }
.quill-toolbar-wrap .ql-fill { fill: var(--text-muted) !important; }
.quill-toolbar-wrap .ql-picker { color: var(--text-muted) !important; }
.quill-editor {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}
.quill-editor .ql-container {
  border: none !important;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  min-height: 280px;
}
.quill-editor .ql-editor {
  min-height: 280px;
  line-height: 1.8;
}
.quill-editor .ql-editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}
.quill-editor .ql-editor td,
.quill-editor .ql-editor th {
  border: 1px solid var(--border);
  padding: 6px 10px;
}
.editor-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}
.requirement-box {
  padding: 10px 16px;
  background: rgba(59,130,246,.08);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.6;
  max-height: 100px;
  overflow-y: auto;
}
.requirement-box.hidden,
.quill-toolbar-wrap.hidden,
.quill-editor.hidden,
.modal.hidden { display: none !important; }

.crawl-stats {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;
}
.crawl-stat {
  font-size: 11px; padding: 4px 10px; border-radius: 4px;
  background: var(--surface2); color: var(--text-muted);
}
.crawl-stat.ok { color: var(--success); }
.crawl-stat.fail { color: var(--danger); opacity: .6; }
.crawl-stat.custom { border: 1px solid var(--primary); }

.sources-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px;
}
.sources-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sources-header h3 { font-size: 15px; }
.schedule-info { font-size: 12px; color: var(--text-muted); }
.sources-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.sources-form input {
  flex: 1; min-width: 140px; padding: 8px 10px; background: var(--bg);
  border: 1px solid var(--border); color: var(--text); border-radius: 6px; font-size: 13px;
}
.batch-import { margin-bottom: 10px; font-size: 13px; color: var(--text-muted); }
.batch-import textarea {
  width: 100%; margin: 8px 0; padding: 8px; background: var(--bg);
  border: 1px solid var(--border); color: var(--text); border-radius: 6px; font-size: 12px;
  font-family: inherit;
}
.schedule-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }
.source-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.source-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--bg); border-radius: 6px; font-size: 12px; gap: 8px;
}
.source-item.disabled { opacity: .5; }
.source-item .url { color: var(--text-muted); font-size: 11px; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.test-preview {
  margin-top: 6px; padding: 6px 8px; background: var(--bg); border-radius: 6px; font-size: 11px;
  max-height: 120px; overflow-y: auto;
}
.test-preview-title { color: var(--text-muted); margin-bottom: 4px; }
.test-preview-item { padding: 2px 0; }
.test-preview-item a { color: var(--primary); text-decoration: none; }
.test-preview-item a:hover { text-decoration: underline; }
.tender-meta-bar { font-size: 12px; color: var(--text-muted); margin: 4px 0 8px; }
.tender-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.toolbar-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.filter-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.filter-item select {
  padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13px;
}
.tender-toolbar .toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.source-actions { display: flex; gap: 4px; flex-shrink: 0; }
.url-hint { font-size: 12px; color: var(--text-muted); margin: 0 0 10px; }
.tender-links { margin: 8px 0; }
.tender-links a { color: var(--primary); font-size: 13px; }
.attach-list { margin-top: 8px; font-size: 12px; }
.attach-list a { color: var(--success); margin-right: 10px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-content {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; width: 520px; max-width: 90vw;
  max-height: 80vh; overflow-y: auto;
}
.modal-content h3 { margin-bottom: 8px; }
.modal-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.modal-select {
  width: 100%; padding: 10px; background: var(--bg);
  border: 1px solid var(--border); color: var(--text); border-radius: 8px;
  margin-bottom: 12px;
}
.pdf-preview {
  font-size: 12px; color: var(--text-muted);
  background: var(--bg); padding: 12px; border-radius: 8px;
  max-height: 200px; overflow-y: auto; margin-bottom: 16px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.polish-bar { padding: 10px 16px; border-top: 1px solid var(--border); }
.polish-bar input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px; border-radius: 6px; font-size: 13px;
}

.settings-form {
  max-width: 640px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-muted); }
.form-group input, .form-group textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 14px;
  font-family: inherit;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.ref-card h4 { margin-bottom: 8px; }
.ref-outline { font-size: 12px; color: var(--text-muted); max-height: 120px; overflow: hidden; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--surface2);
  border: 1px solid var(--border); padding: 12px 20px; border-radius: 8px;
  font-size: 13px; opacity: 0; transform: translateY(10px); transition: .3s;
  pointer-events: none; z-index: 999; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }

.empty { text-align: center; padding: 48px; color: var(--text-muted); font-size: 14px; }

@media (max-width: 1100px) {
  .editor-layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { width: 200px; }
}
