:root {
  --accent: #059669;
  --accent-dark: #047857;
  --nav-bg: #064e3b;
  --nav-text: #ecfdf5;
  --bg: #f8faf9;
  --surface: #ffffff;
  --border: #e2e8e5;
  --text: #1f2937;
  --text-muted: #6b7280;
  --yellow-bg: #fefce8;
  --yellow-border: #fde68a;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --red: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent-dark); }

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
}
button:hover { background: #f1f5f4; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
button.primary:hover { background: var(--accent-dark); }

button.danger {
  color: var(--red);
  border-color: #fecaca;
}
button.danger:hover { background: #fef2f2; }

button.ghost {
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 0.25rem; }

/* ---- nav ---- */

.nav {
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
}
.nav .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: white;
  text-decoration: none;
}
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a, .nav-links button {
  color: var(--nav-text);
  text-decoration: none;
  font-size: 0.9rem;
  background: none;
  border: none;
  padding: 0.25rem 0;
}
.nav-links a:hover, .nav-links button:hover { color: white; text-decoration: underline; }
.nav-role {
  font-size: 0.75rem;
  background: rgba(255,255,255,0.15);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}
.container.wide { max-width: 1200px; }

/* ---- login ---- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 1.5rem;
  color: var(--nav-bg);
}
.field { margin-bottom: 1rem; }
.error-text { color: var(--red); font-size: 0.85rem; margin-top: 0.5rem; }

/* ---- progress ---- */

.progress-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ---- queue ---- */

.queue-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }

.search-input { max-width: 260px; }

.section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 1.75rem 0 0.75rem;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.6rem;
}
.article-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.6rem;
}
.article-title { font-weight: 600; font-size: 1rem; }
.article-title a { color: var(--text); text-decoration: none; }
.article-title a:hover { color: var(--accent-dark); }

.lang-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.lang-badge {
  font-size: 0.75rem;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
}
.lang-badge.done { background: var(--green-bg); border-color: var(--green-border); color: var(--accent-dark); }
.lang-badge.pending { background: var(--yellow-bg); border-color: var(--yellow-border); }

.empty-state { color: var(--text-muted); padding: 2rem 0; text-align: center; }

/* ---- editor ---- */

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.editor-header h1 { font-size: 1.2rem; margin: 0; }
.back-link { font-size: 0.85rem; text-decoration: none; color: var(--text-muted); }

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.editor-toolbar .stats { font-size: 0.85rem; color: var(--text-muted); }
.toolbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.segment-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.segment-card.status-unverified { background: var(--yellow-bg); border-color: var(--yellow-border); }
.segment-card.status-verified { background: var(--green-bg); border-color: var(--green-border); }

.segment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.segment-meta .badges { display: flex; gap: 0.4rem; }

.badge {
  display: inline-block;
  border-radius: 5px;
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge.verified { background: var(--accent); color: white; }
.badge.unverified { background: #ca8a04; color: white; }
.badge.human { background: #1d4ed8; color: white; }
.badge.machine { background: #64748b; color: white; }
.badge.field { background: #e2e8e5; color: var(--text-muted); }

.segment-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: rgba(0,0,0,0.06);
}
.segment-col {
  background: var(--surface);
  padding: 0.9rem 1rem;
}
.segment-col .col-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  letter-spacing: 0.03em;
}
.segment-source { white-space: pre-wrap; font-size: 0.92rem; }
.segment-col textarea { min-height: 90px; resize: vertical; }

.char-counter { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.3rem; text-align: right; }
.char-counter.over { color: var(--red); font-weight: 600; }

.segment-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid rgba(0,0,0,0.06);
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .segment-body { grid-template-columns: 1fr; }
}

/* ---- view tabs ---- */

.view-tabs { display: flex; gap: 0.4rem; }
.view-tabs button.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ---- article preview ---- */

.article-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  max-width: 760px;
  margin: 0 auto;
  line-height: 1.7;
}
.article-preview h2.preview-seg { display: block; font-size: 1.4rem; margin: 0 0 0.75rem; }
.article-preview .preview-description { display: block; color: var(--text-muted); font-style: italic; margin-bottom: 1.25rem; }
.article-preview-body p, .article-preview-body li, .article-preview-body h1, .article-preview-body h2, .article-preview-body h3 { margin: 0 0 0.9rem; }
.article-preview-body img { max-width: 100%; height: auto; display: block; margin: 0.5rem 0; }
.preview-seg a { color: var(--accent-dark); }

.preview-seg {
  cursor: pointer;
  border-radius: 4px;
  padding: 0.05rem 0.2rem;
  margin: 0 -0.2rem;
}
.preview-seg.status-unverified { background: var(--yellow-bg); box-shadow: 0 0 0 1px var(--yellow-border) inset; }
.preview-seg.status-verified { background: var(--green-bg); box-shadow: 0 0 0 1px var(--green-border) inset; }
.preview-seg:hover { filter: brightness(0.96); }

/* ---- segment popover (article view click-to-edit) ---- */

.segment-popover {
  position: absolute;
  z-index: 150;
  width: min(420px, 90vw);
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  border-radius: var(--radius);
}
.segment-popover .segment-card { margin-bottom: 0; }
.segment-popover .segment-body { grid-template-columns: 1fr; }

/* ---- account / forms ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  max-width: 480px;
}
.card h2 { font-size: 1.05rem; margin: 0 0 1rem; }
.form-row { display: flex; gap: 0.75rem; }
.form-row .field { flex: 1; }

/* ---- users table ---- */

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th { background: var(--bg); font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); }
tr:last-child td { border-bottom: none; }
.role-pill { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); }
.role-pill.admin { background: #ede9fe; border-color: #ddd6fe; color: #5b21b6; }
.role-pill.super-admin { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

/* ---- modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

.lang-radio-group { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.lang-radio-group label { display: flex; align-items: center; gap: 0.3rem; font-weight: 400; color: var(--text); }
.lang-radio-group input { width: auto; }

/* ---- toasts ---- */

.toasts {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: #111827;
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 220px;
}
.toast.success { background: var(--accent-dark); }
.toast.error { background: #b91c1c; }

/* ---- result panels ---- */

.result-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.result-panel h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.result-stats { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.result-stat { font-size: 0.85rem; }
.result-stat b { display: block; font-size: 1.3rem; color: var(--accent-dark); }

.spinner-inline { font-size: 0.8rem; color: var(--text-muted); }

/* ---- admin: push to Intercom ---- */

.hint-text { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 1rem; }

.push-run-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.push-run-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.push-run-summary { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.push-run-card table { border: none; border-radius: 0; }
