/* ===================================================================
   Admin Dashboard — Component Styles
   Metric stacks, tables, logs, crisis items, badges, retention heatmap,
   funnel bars, review forms, refresh toggle, role badge, delta badge
   =================================================================== */

/* ===== Metric Stack ===== */

.metric-stack,
.table-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid rgba(74, 60, 46, 0.08);
}

.metric-row:first-child,
.table-row:first-child {
  border-top: 0;
}

.metric-main {
  min-width: 0;
}

.metric-title,
.table-key {
  margin: 0;
  font-weight: 600;
}

.metric-meta,
.table-meta {
  margin: 5px 0 0;
  color: var(--subtle);
  font-size: 13px;
  line-height: 1.4;
}

.metric-meter {
  margin-top: 10px;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(35, 27, 20, 0.08);
  overflow: hidden;
}

.metric-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(11, 122, 98, 0.34), #0b7a62);
}

.metric-value {
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--muted);
}

/* ===== Tables ===== */

.table-head,
.table-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) repeat(3, minmax(72px, 0.8fr));
  gap: 12px;
  align-items: center;
}

.table-head {
  padding: 0 0 10px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.table-row {
  padding: 12px 0;
  border-top: 1px solid rgba(74, 60, 46, 0.08);
}

.table-number {
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: var(--muted);
}

/* ===== Log Table ===== */

.log-table {
  display: flex;
  flex-direction: column;
}

.log-head,
.log-row {
  display: grid;
  grid-template-columns: 124px 120px 92px minmax(0, 1fr) 130px 180px;
  gap: 12px;
  align-items: center;
}

.log-head {
  padding: 0 0 10px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.log-row {
  padding: 12px 0;
  border-top: 1px solid rgba(74, 60, 46, 0.08);
}

/* ===== Error Table ===== */

.error-table-head,
.error-table-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 80px 120px;
  gap: 12px;
  align-items: center;
}

.error-table-head {
  padding: 0 0 10px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.error-table-row {
  padding: 12px 0;
  border-top: 1px solid rgba(74, 60, 46, 0.08);
}

/* ===== Crisis Entries ===== */

.crisis-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.crisis-item {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  border-left: 4px solid var(--color-error);
  background: rgba(255, 255, 255, 0.6);
  transition: background-color 160ms ease;
}

.crisis-item:hover {
  background: rgba(255, 255, 255, 0.85);
}

.crisis-item--reviewed {
  border-left-color: var(--color-success);
  opacity: 0.75;
}

.crisis-item__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.crisis-item__date {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.crisis-item__emotion {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--color-error-soft);
  color: var(--color-error);
}

.crisis-item__text {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.crisis-item__review-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--color-success);
  font-weight: 600;
}

.crisis-item__review-btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 14px;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.7);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}

.crisis-item__review-btn:hover {
  background: var(--accent);
  color: #fbfffd;
}

/* ===== Status Badge ===== */

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-badge--success {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-badge--error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ===== Delta Badge ===== */

.delta-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-family: "IBM Plex Mono", monospace;
  vertical-align: middle;
}

.delta-badge--positive {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.delta-badge--negative {
  background: var(--color-error-soft);
  color: var(--color-error);
}

.delta-badge--neutral {
  background: rgba(142, 121, 102, 0.12);
  color: var(--subtle);
}

/* ===== Role Badge ===== */

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
}

.role-badge:empty {
  display: none;
}

/* ===== Refresh Toggle ===== */

.refresh-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--panel-border);
}

.refresh-toggle__option {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}

.refresh-toggle__option:hover {
  color: var(--text);
}

.refresh-toggle__option.is-active {
  background: var(--accent);
  color: #fbfffd;
}

/* ===== Retention Heatmap ===== */

.retention-container {
  overflow-x: auto;
}

.retention-head,
.retention-row {
  display: grid;
  grid-template-columns: 100px 60px repeat(5, 1fr);
  gap: 6px;
  align-items: center;
  padding: 8px 0;
}

.retention-head {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
}

.retention-row {
  border-top: 1px solid rgba(74, 60, 46, 0.08);
}

.retention-row__cohort {
  font-size: 13px;
  font-weight: 600;
  font-family: "IBM Plex Mono", monospace;
}

.retention-row__count {
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}

.retention-cell {
  text-align: center;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: rgba(11, 122, 98, calc(var(--intensity, 0) / 100 * 0.6));
  color: var(--text);
  transition: background-color 200ms ease;
}

/* ===== Review Form ===== */

.review-form {
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--panel-border);
}

.review-form__textarea {
  width: 100%;
  min-height: 60px;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
  background: #fff;
  color: var(--text);
}

.review-form__textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.review-form__actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.review-form__submit {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fbfffd;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 160ms ease;
}

.review-form__submit:hover {
  opacity: 0.88;
}

.review-form__submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.review-form__cancel {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.review-form__cancel:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* ===== Responsive — Components ===== */

@media (max-width: 1080px) {
  .log-head,
  .log-row {
    grid-template-columns: 112px 100px 84px minmax(0, 1fr);
  }

  .log-row > :nth-child(5),
  .log-row > :nth-child(6),
  .log-head > :nth-child(5),
  .log-head > :nth-child(6) {
    display: none;
  }

  .error-table-head,
  .error-table-row {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 80px;
  }

  .error-table-head > :nth-child(4),
  .error-table-row > :nth-child(4) {
    display: none;
  }

  .retention-head,
  .retention-row {
    grid-template-columns: 80px 50px repeat(5, 1fr);
    font-size: 12px;
  }
}

@media (max-width: 720px) {
  .metric-row,
  .table-head,
  .table-row {
    grid-template-columns: 1fr;
  }

  .table-head {
    display: none;
  }

  .table-number,
  .metric-value {
    text-align: left;
  }

  .log-head {
    display: none;
  }

  .log-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .error-table-head {
    display: none;
  }

  .error-table-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .retention-head {
    display: none;
  }

  .retention-head,
  .retention-row {
    grid-template-columns: 1fr;
  }

  .retention-cell {
    display: inline-block;
    margin: 2px;
  }

  .refresh-toggle {
    order: -1;
  }
}

/* ===== Help Tip (?) ===== */

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 4px;
  border-radius: 50%;
  background: rgba(74, 60, 46, 0.1);
  color: var(--subtle);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  position: relative;
}

.help-tip:hover {
  background: var(--accent);
  color: #fbfffd;
}

.help-tip:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--text);
  color: #fffdf9;
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
  max-width: 280px;
  white-space: normal;
  line-height: 1.5;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  pointer-events: none;
}
