:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #111827;
  --primary-hover: #1f2937;
  --accent: #2563eb;
  --x-blue: #1d9bf0;
  --success: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --font: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* Top Bar */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 17px;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 13px;
  margin-left: 6px;
}

.stats-bar {
  font-size: 12px;
  color: var(--text-muted);
}

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

/* Buttons & Inputs */
.btn, .btn-mini {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn {
  padding: 7px 13px;
  font-size: 13px;
}

.btn-mini {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn:hover, .btn-mini:hover {
  background: #f1f5f9;
}

.btn:disabled, .btn-mini:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.btn-secondary:hover {
  background: #dbeafe;
}

.btn-ghost {
  background: transparent;
}

.btn-success {
  background: #ecfdf5;
  color: var(--success);
  border-color: #a7f3d0;
}

.btn-success:hover {
  background: #d1fae5;
}

.btn-x {
  background: #e8f5fe;
  color: #0c7abf;
  border-color: #bae6fd;
}

.btn-x:hover {
  background: #d3edfd;
}

.btn-danger-ghost {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}

.btn-danger-ghost:hover {
  background: #fef2f2;
  border-color: #fecaca;
}

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

.input-compact, .select-compact {
  padding: 5px 9px;
  font-size: 12px;
}

.input-full {
  width: 100%;
}

.input-flex {
  flex: 1;
  min-width: 160px;
}

/* Main Layout */
.workspace {
  height: calc(100vh - 60px);
  display: grid;
  grid-template-columns: 380px 1fr;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-group {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pill-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill, .chip {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.pill.active, .chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.search-sort-row {
  display: flex;
  gap: 6px;
}

.input-search {
  flex: 1;
  padding: 5px 10px;
  font-size: 12px;
}

.item-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-list {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.item-card:hover {
  border-color: #94a3b8;
  background: var(--surface-muted);
}

.item-card.selected {
  border-color: var(--primary);
  background: #f8fafc;
  box-shadow: 0 0 0 1px var(--primary);
}

.item-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}

.item-card-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
}

.badge-weibo { background: #fef2f2; color: #dc2626; }
.badge-bilibili { background: #eff6ff; color: #0284c7; }
.badge-xiaohongshu { background: #fff1f2; color: #e11d48; }
.badge-manual { background: #f3e8ff; color: #7e22ce; }

.status-dot {
  font-size: 11px;
  color: var(--text-muted);
}

.status-dot.drafted { color: var(--accent); font-weight: 600; }
.status-dot.published { color: var(--success); font-weight: 600; }

.score-pill {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.score-high { background: #d1fae5; color: #065f46; }
.score-mid { background: #fef3c7; color: #92400e; }
.score-low { background: #f1f5f9; color: #64748b; }

.item-card-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.item-card-ext {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
}

.item-card-ext:hover {
  color: var(--accent);
}

/* Studio */
.studio {
  overflow-y: auto;
  padding: 16px 20px 28px;
}

.studio-empty {
  height: 100%;
  display: grid;
  place-items: center;
}

.studio-empty-card {
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}

.studio-empty-card h2 {
  margin: 0 0 8px;
  font-size: 19px;
}

.studio-empty-card p {
  margin: 0 0 16px;
  color: var(--text-muted);
}

.empty-tips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-muted);
  border-radius: 10px;
  padding: 14px;
  font-size: 13px;
}

.studio-content {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Source Inspector */
.source-inspector {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.inspector-header {
  padding: 10px 14px;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  gap: 10px;
}

.inspector-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-tag {
  font-size: 12px;
  color: var(--text-muted);
}

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

.source-link-pill {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.source-link-pill:hover {
  background: #dbeafe;
}

.inspector-body {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.detail-title {
  margin: 0 0 6px;
  font-size: 17px;
}

.detail-summary {
  margin: 0 0 10px;
  color: #334155;
  white-space: pre-wrap;
  font-size: 13px;
}

.edit-summary-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.edit-summary-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.thin-tip-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  margin-bottom: 10px;
}

.detail-score-reason {
  background: #ecfdf5;
  color: #065f46;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 10px;
}

.comments-panel {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.comments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.comments-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
}

.comments-btns {
  display: flex;
  gap: 6px;
}

.add-comment-box {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: flex-start;
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 170px;
  overflow-y: auto;
}

.comment-row {
  background: var(--surface-muted);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.comment-likes {
  color: var(--text-muted);
  white-space: nowrap;
}

/* Controls Bar */
.controls-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tone-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.control-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.import-box {
  background: var(--surface);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.import-box-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
}

.import-box textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
}

.import-box-actions {
  display: flex;
  justify-content: flex-end;
}

/* Tabs */
.studio-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  gap: 10px;
}

.tabs-left {
  display: flex;
  gap: 6px;
}

.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.draft-meta-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.no-draft-banner {
  background: var(--surface);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}

.draft-editor {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}

.section-head h3 {
  margin: 0;
  font-size: 14px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hint-inline {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 6px;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.glossary-card {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12px;
}

.glossary-top {
  font-weight: 700;
  margin-bottom: 3px;
}

.glossary-eq {
  color: var(--accent);
}

.glossary-exp {
  color: var(--text-muted);
}

.tweet-textarea {
  width: 100%;
  resize: vertical;
  line-height: 1.55;
  font-size: 14px;
}

.char-counter {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}

.char-counter.over {
  color: var(--danger);
  font-weight: 700;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thread-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-muted);
}

.thread-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
}

.source-reply-block {
  background: #f8fafc;
}

/* Card Studio */
.card-studio-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}

.card-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding-bottom: 7px;
}

.card-comments-picker {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 160px;
  overflow-y: auto;
}

.picker-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12px;
  background: var(--surface-muted);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.card-export-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-preview-wrap {
  background: #e2e8f0;
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.card-preview-meta {
  font-size: 12px;
  color: #475569;
  font-weight: 600;
}

#card-canvas {
  max-width: 100%;
  max-height: 68vh;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 14px 35px rgba(15, 23, 42, 0.16);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.25);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.test-status {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 600;
}

/* Video Modal */
.video-url-row {
  display: flex;
  gap: 8px;
}

.video-preview-card {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.video-preview-title {
  font-weight: 700;
  font-size: 14px;
}

.video-preview-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.video-preview-desc {
  font-size: 12px;
  color: #334155;
  max-height: 76px;
  overflow-y: auto;
}

.video-result-banner {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  word-break: break-all;
}

.video-dl-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.video-dl-row {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.video-dl-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

/* OCR Panel in Manual Modal */
.ocr-panel {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ocr-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
}

.screenshot-dropzone {
  border: 1.5px dashed #94a3b8;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
}

.screenshot-dropzone:hover {
  border-color: var(--accent);
  color: var(--text);
}

.screenshot-thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.thumb-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
}

.ocr-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.manual-json-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  max-width: 380px;
}

.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 310px 1fr;
  }
  .card-studio-layout {
    grid-template-columns: 1fr;
  }
}

/* Auth Gate & Key Clear Controls */
.auth-gate {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-error {
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  padding: 9px 14px;
}

.key-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-link-danger {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.btn-link-danger:hover {
  text-decoration: underline;
}
