@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0f14;
  --surface:   #161a22;
  --surface2:  #1e2330;
  --border:    #2a3045;
  --accent:    #6c8aff;
  --accent2:   #a78bfa;
  --success:   #34d399;
  --warn:      #fbbf24;
  --danger:    #f87171;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --radius:    12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
  color: var(--text);
}

.header-logo .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 0 10px rgba(108, 138, 255, 0.6);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(108,138,255,.5); }
  50%       { box-shadow: 0 0 18px rgba(108,138,255,.9); }
}

.header-badge {
  padding: 2px 10px;
  background: rgba(108,138,255,.12);
  border: 1px solid rgba(108,138,255,.3);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: .5px;
}

.header-spacer { flex: 1; }

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
}

/* ── Main split ── */
.main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow: hidden;
}

/* ── Panel ── */
.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.panel-left  { 
  border-right: 1px solid var(--border); 
  overflow-y: auto;
}

.panel-left::-webkit-scrollbar { width: 4px; }
.panel-left::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.panel-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  flex: 1;
}

.panel-count {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--surface2);
  border-radius: 99px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

/* ── Textarea ── */
.input-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  overflow: hidden;
}

#posts-input {
  flex: 1;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.7;
  resize: none;
  outline: none;
  transition: border-color .2s;
}

#posts-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(108,138,255,.1);
}

#posts-input::placeholder { color: var(--muted); }

/* ── Image Upload ── */
.image-upload-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px dashed var(--muted);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  width: max-content;
  transition: all .2s;
}

.btn-upload:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.image-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

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

.image-preview-item .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.image-preview-item .remove-btn:hover {
  background: rgba(248, 113, 113, 0.8);
}

/* ── Run button ── */
.btn-run {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: opacity .2s, transform .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-run:hover  { opacity: .9; transform: translateY(-1px); }
.btn-run:active { transform: translateY(0); }

.btn-run.loading {
  pointer-events: none;
  opacity: .7;
}

.btn-icon { font-size: 16px; }

/* ── Output area ── */
.output-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.output-area::-webkit-scrollbar { width: 5px; }
.output-area::-webkit-scrollbar-track { background: transparent; }
.output-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Empty state ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}

.empty-icon { font-size: 40px; opacity: .4; }

.empty-state p {
  font-size: 13px;
  line-height: 1.8;
  max-width: 260px;
}

/* ── Post card ── */
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  animation: slideIn .25s ease forwards;
  opacity: 0;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.card-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
}

.card-name {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
}

.cat-sell_offer, .cat-bán_hàng      { background: rgba(52,211,153,.12); color: var(--success); border: 1px solid rgba(52,211,153,.25); }
.cat-buy_request, .cat-tìm_mua     { background: rgba(251,191,36,.12);  color: var(--warn);    border: 1px solid rgba(251,191,36,.25); }
.cat-service_offer, .cat-dịch_vụ   { background: rgba(108,138,255,.12); color: var(--accent);  border: 1px solid rgba(108,138,255,.25); }
.cat-question, .cat-câu_hỏi        { background: rgba(167,139,250,.12); color: var(--accent2); border: 1px solid rgba(167,139,250,.25); }
.cat-job_offer, .cat-tuyển_dụng     { background: rgba(248,113,113,.12); color: var(--danger);  border: 1px solid rgba(248,113,113,.25); }
.cat-other, .cat-khác              { background: rgba(100,116,139,.12); color: var(--muted);   border: 1px solid rgba(100,116,139,.25); }

.card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }

.card-row {
  display: flex;
  gap: 8px;
  font-size: 12.5px;
}

.card-label {
  color: var(--muted);
  min-width: 80px;
  font-weight: 500;
  flex-shrink: 0;
}

.card-value { color: var(--text); }

.card-value.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--success);
}

.card-details {
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Loading spinner ── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
}

.btn-run.loading .spinner { display: block; }
.btn-run.loading .btn-icon,
.btn-run.loading .btn-label { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Raw JSON toggle ── */
.btn-raw {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-raw:hover { border-color: var(--accent); color: var(--accent); }

.raw-block {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.raw-block.visible { display: block; }

pre.raw-json {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
}

/* ── JSON Panel ── */
.json-panel {
  display: none;
  flex-direction: column;
  background: var(--surface);
  flex: 1;
  overflow: hidden;
}

.json-panel.visible {
  display: flex;
  animation: slideIn .25s ease forwards;
}

.json-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}

.json-panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}

.btn-download {
  padding: 4px 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: opacity .2s, transform .15s;
  letter-spacing: .3px;
}

.btn-download:hover  { opacity: .88; transform: translateY(-1px); }
.btn-download:active { transform: translateY(0); }

.json-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg);
  margin: 0;
}

.json-panel-body::-webkit-scrollbar { width: 4px; }
.json-panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Training Section ── */
.training-section {
  background: var(--surface);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.training-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}

.training-header:hover {
  background: var(--surface2);
}

.training-icon { font-size: 14px; }

.training-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .7px;
  flex: 1;
}

.training-badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  background: var(--muted);
  color: var(--bg);
  transition: background .2s;
}

.training-chevron {
  font-size: 13px;
  color: var(--muted);
  transition: transform .2s;
}

.training-body {
  padding: 0 16px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.training-hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.6;
}

.training-hint code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  background: rgba(108,138,255,.1);
  padding: 1px 5px;
  border-radius: 4px;
}

#training-input {
  width: 100%;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.7;
  resize: none;
  outline: none;
  transition: border-color .2s;
}

#training-input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px rgba(167,139,250,.1);
}

#training-input::placeholder { color: var(--muted); opacity: .6; }

/* ── Training Save Row ── */
.training-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.btn-save-training {
  padding: 6px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color .2s, color .2s, opacity .2s;
  white-space: nowrap;
}

.btn-save-training:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.btn-save-training:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.training-save-status {
  font-size: 11.5px;
  font-weight: 500;
  transition: color .2s;
}

.training-save-status.saving { color: var(--muted); }
.training-save-status.saved  { color: var(--success); }
.training-save-status.error  { color: var(--danger); }

/* Export / Import tool buttons */
.btn-training-tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 11px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .2s, color .2s;
  white-space: nowrap;
  user-select: none;
}

.btn-training-tool:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

/* ── Init Section ── */
.init-section {
  background: var(--surface);
  flex: 1;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
}

.init-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface2);
}

.init-icon { font-size: 14px; }

.init-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .7px;
  flex: 1;
}

.init-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

#init-input {
  width: 100%;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.7;
  resize: none;
  outline: none;
  transition: border-color .2s;
}

#init-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(108,138,255,.1);
}

.init-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.btn-save-init {
  padding: 6px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color .2s, color .2s, opacity .2s;
  white-space: nowrap;
}

.btn-save-init:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-save-init:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.init-save-status {
  font-size: 11.5px;
  font-weight: 500;
  transition: color .2s;
}

.init-save-status.saving { color: var(--muted); }
.init-save-status.saved  { color: var(--success); }
.init-save-status.error  { color: var(--danger); }

/* ── Evaluation Box ── */
.evaluation-box {
  margin-bottom: 12px;
  padding: 14px;
  background: rgba(108, 138, 255, 0.05);
  border: 1px solid rgba(108, 138, 255, 0.2);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.eval-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.eval-status {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  min-width: 150px;
}

.eval-status:focus { border-color: var(--accent); }

.eval-reason {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
}

.eval-reason:focus { border-color: var(--accent); }

.btn-add-training {
  padding: 6px 16px;
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.btn-add-training:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* ── Responsive Fixes ── */
@media (max-width: 1024px) {
  .main { grid-template-columns: 1fr; overflow-y: auto; }
  .app { height: auto; overflow: visible; }
  .panel-left { border-right: none; border-bottom: 1px solid var(--border); }
}

