:root {
  --bg: #f7f4ef;
  --text: #1f1f1f;
  --accent: #114b5f;
  --accent-2: #e07a5f;
  --border: #ded7cf;
  --card: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding-top: 56px;
  font-family: "IBM Plex Sans", "Source Sans 3", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f7f4ef 0%, #f2efe8 100%);
}

.header {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: #fffaf3;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  flex: 1;
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px 12px;
}

.nav a {
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
}

.container {
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 12px;
}

.card-title { font-size: 14px; color: #555; }
.card-value { font-size: 28px; font-weight: 700; }

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

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
}

button.primary { background: var(--accent-2); }
button.danger { background: #c44536; }

.form {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 12px;
}

.form input,
.form textarea,
.form select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

h1, h2 { margin-top: 0; }

.hint {
  color: #5a5a5a;
  margin-bottom: 16px;
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  background: #fffaf3;
}

.alert.success {
  border-color: #b9d7bf;
  background: #eef8f0;
}

.alert.error {
  border-color: #e6b1aa;
  background: #fdecea;
}

.form-narrow {
  max-width: 420px;
}

.form-inline {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.form-inline input,
.form-inline select {
  width: auto;
}

.actions-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.nav-user {
  margin-left: 12px;
  padding: 6px 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #ffffff;
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 16px;
}

.pagination a {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 6px 10px;
  border-radius: 8px;
}

.pagination .current {
  font-weight: 600;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.post-text {
  max-width: 600px;
  white-space: pre-wrap;
}

.code-block {
  background: #fffaf3;
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}

.event {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--card);
}

.footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: #fffaf3;
}

/* Narrative topic tag in event header */
.narrative-topic {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  margin-left: 10px;
  vertical-align: middle;
}

/* AI narrative analysis block */
.ai-narrative {
  background: #f0f7fa;
  border: 1px solid #c4dde6;
  border-radius: 10px;
  padding: 14px 16px;
  margin: 10px 0 14px;
  font-size: 14px;
}

.ai-narrative-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.ai-summary {
  margin: 6px 0;
  line-height: 1.5;
}

.ai-techniques,
.ai-audience,
.ai-claims {
  margin-top: 8px;
}

.ai-claims ul {
  margin: 4px 0 0 18px;
  padding: 0;
}

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  margin: 2px 3px;
}

.tag-technique {
  background: #fce4db;
  color: #9c3a1a;
  border: 1px solid #f0c4b0;
}

/* Confidence badges */
.confidence {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.confidence-high {
  background: #fde2e2;
  color: #b91c1c;
  border: 1px solid #f5b5b5;
}

.confidence-medium {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.confidence-low {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

/* Composite score color badges */
.score-high {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.score-medium {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.score-low {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  background: #fde2e2;
  color: #b91c1c;
  border: 1px solid #f5b5b5;
}

/* Composite weights info line */
.composite-weights-info {
  font-size: 13px;
  color: #5a5a5a;
  margin-top: 8px;
}

/* Pipeline progress */
.pipeline-progress {
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.pipeline-step + .pipeline-step {
  border-top: 1px solid var(--border);
}

.step-indicator {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.step-pending {
  background: #e0ddd8;
}

.step-running {
  border: 3px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
}

.step-done {
  background: #16a34a;
}

.step-done::after {
  content: "\2713";
  color: #fff;
  font-weight: 700;
}

.step-error {
  background: #c44536;
}

.step-error::after {
  content: "\2717";
  color: #fff;
  font-weight: 700;
}

.step-label {
  font-weight: 500;
}

.step-result {
  margin-left: auto;
  font-size: 13px;
  color: #5a5a5a;
}

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

/* Narrative cards */
.narrative-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
  padding: 1.2rem;
}
.narrative-header h2 { margin: 0 0 0.3rem 0; font-size: 1.15rem; }
.narrative-meta {
  font-size: 0.85rem;
  color: #777;
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.narrative-event {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--border);
}
.event-info { display: flex; gap: 1rem; margin-bottom: 0.4rem; font-size: 0.85rem; }
.event-time { color: var(--accent); font-weight: 600; }
.event-topic { color: #555; }
table.compact { font-size: 0.85rem; }
table.compact td, table.compact th { padding: 0.3rem 0.6rem; }

/* User management cards */
.user-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.user-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.user-card-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-card-name {
  font-size: 18px;
  font-weight: 700;
}

.user-card-meta {
  font-size: 13px;
  color: #777;
}

.user-card-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.user-action-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-action-group label {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.user-action-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-action-group select,
.user-action-group input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
}

.password-reset-form {
  display: grid;
  gap: 8px;
}

button.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}

button.btn-outline:hover {
  background: var(--accent);
  color: #fff;
}

.tag-admin {
  background: #e8dff5;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
}

.tag-user {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #7dd3fc;
}

.tag-active {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.tag-inactive {
  background: #fde2e2;
  color: #b91c1c;
  border: 1px solid #f5b5b5;
}

/* ── Hamburger menu toggle ── */
.nav-toggle {
  display: none;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  margin-left: auto;
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
  body { padding-top: 50px; }

  .header {
    padding: 10px 14px;
    flex-wrap: wrap;
  }

  .brand { font-size: 15px; }

  .nav-toggle { display: block; }

  .nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
  }

  .nav.open { display: flex; }

  .nav a {
    display: block;
    width: 100%;
    padding: 8px 4px;
    border-radius: 6px;
  }

  .nav a:active { background: rgba(0,0,0,0.05); }

  .nav-right {
    margin-left: 0;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }

  .nav-user {
    margin-left: 0;
    margin-bottom: 4px;
  }

  .container { padding: 14px; }

  h1 { font-size: 22px; }
  h2 { font-size: 18px; }

  /* User cards */
  .user-card { padding: 14px; }

  .user-card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .user-card-actions {
    grid-template-columns: 1fr;
  }

  .user-action-row {
    flex-direction: column;
  }

  .user-action-row button,
  .user-action-row select {
    width: 100%;
  }

  .user-action-group button {
    width: 100%;
    padding: 12px 14px;
  }

  .user-action-group select,
  .user-action-group input {
    padding: 12px 10px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  /* Forms */
  .form-narrow { max-width: 100%; }

  .form input,
  .form textarea,
  .form select {
    font-size: 16px;
    padding: 12px;
  }

  .form button {
    width: 100%;
    padding: 14px;
  }

  /* Tables */
  table { font-size: 14px; }
  th, td { padding: 8px 6px; }

  /* Cards grid */
  .cards {
    grid-template-columns: 1fr 1fr;
  }

  /* Pagination */
  .pagination { flex-wrap: wrap; }

  /* Pipeline */
  .pipeline-step { flex-wrap: wrap; }
  .step-result { margin-left: 32px; }
}

@media (max-width: 420px) {
  .container { padding: 10px; }

  .cards { grid-template-columns: 1fr; }

  .user-card-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .user-card-name { font-size: 16px; }
}
