/* =====================================================================
   Activity history — drawer timeline (.ah-*), the Activity page feed (.ahf-*), and the
   "History" buttons on review cards (.ah-open). Loaded on every admin page by _Layout.
   ===================================================================== */
:root {
  --ah-ink: #0f172a;
  --ah-muted: #64748b;
  --ah-faint: #94a3b8;
  --ah-line: #e2e8f0;
  --ah-soft: #f8fafc;
  --ah-ok: #16a34a;
  --ah-bad: #dc2626;
  --ah-warn: #d97706;
  --ah-info: #2563eb;
  --ah-note: #7c3aed;
  --ah-comment: #0d9488;
}

/* ---------- History button on cards ---------- */
.ah-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2rem;
  padding: 0 0.7rem;
  border: 1px solid var(--ah-line);
  border-radius: 8px;
  background: #fff;
  color: var(--ah-ink);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.ah-open:hover {
  border-color: #cbd5e1;
  background: var(--ah-soft);
}

.ah-open .bi {
  color: var(--ah-note);
}

.ah-open--block {
  width: 100%;
}

.ah-open--icon {
  width: 2rem;
  padding: 0;
}

/* ---------- Drawer ---------- */
.ah-drawer.offcanvas-end {
  width: min(520px, 100vw);
  border-left: 1px solid var(--ah-line);
}

.ah-drawer__header {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--ah-line);
}

.ah-drawer__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--ah-ink);
  font-size: 1rem;
  font-weight: 700;
}

.ah-drawer__title .bi {
  color: var(--ah-note);
}

.ah-drawer__body {
  padding: 0;
  background: var(--ah-soft);
}

.ah-loading,
.ah-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 3rem 1.25rem;
  color: var(--ah-muted);
  font-size: 0.9rem;
  text-align: center;
}

.ah-loading {
  flex-direction: row;
  justify-content: center;
}

.ah-empty .bi {
  color: var(--ah-faint);
  font-size: 1.6rem;
}

.ah-empty p {
  margin: 0;
}

/* Subject header */
.ah-subject {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--ah-line);
  background: #fff;
}

.ah-subject__icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 1.1rem;
}

.ah-subject__copy {
  flex: 1 1 auto;
  min-width: 0;
}

.ah-subject__kind {
  margin: 0;
  color: var(--ah-faint);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.ah-subject__title {
  margin: 0.1rem 0 0.35rem;
  color: var(--ah-ink);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.ah-subject__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.85rem;
  margin: 0;
  color: var(--ah-muted);
  font-size: 0.8rem;
}

.ah-subject__meta > span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ah-pill {
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--ah-ink);
}

.ah-subject__open {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--ah-line);
  border-radius: 8px;
  color: var(--ah-muted);
}

.ah-subject__open:hover {
  color: var(--ah-ink);
  background: var(--ah-soft);
}

/* Internal note */
.ah-note {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--ah-line);
  background: #fff;
}

.ah-note textarea {
  width: 100%;
  min-height: 3.2rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--ah-line);
  border-radius: 10px;
  background: #fffdf7;
  color: var(--ah-ink);
  font-size: 0.86rem;
  resize: vertical;
}

.ah-note textarea:focus {
  border-color: #c4b5fd;
  outline: 3px solid rgba(124, 58, 237, 0.12);
}

.ah-note__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.45rem;
}

.ah-note__hint {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--ah-faint);
  font-size: 0.75rem;
}

.ah-note__msg {
  margin: 0.4rem 0 0;
  color: var(--ah-bad);
  font-size: 0.8rem;
}

/* Tabs */
.ah-tabs {
  display: flex;
  gap: 0.3rem;
  padding: 0.65rem 1.1rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--ah-line);
  background: #fff;
}

.ah-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ah-muted);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.ah-tab span {
  min-width: 1.2rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 0.7rem;
  text-align: center;
}

.ah-tab.is-active {
  border-color: #cbd5e1;
  background: var(--ah-soft);
  color: var(--ah-ink);
}

/* Timeline */
.ah-list {
  position: relative;
  margin: 0;
  padding: 0.6rem 1.1rem 1.5rem;
  list-style: none;
}

.ah-day {
  margin: 0.7rem 0 0.35rem;
  color: var(--ah-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ah-item {
  position: relative;
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  gap: 0.65rem;
  padding-bottom: 0.85rem;
}

/* Rail between dots */
.ah-item::before {
  content: "";
  position: absolute;
  top: 2rem;
  bottom: 0;
  left: calc(1rem - 1px);
  width: 2px;
  background: var(--ah-line);
}

.ah-item:last-child::before {
  display: none;
}

.ah-item__dot {
  --tone: var(--ah-faint);
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 2px solid #fff;
  border-radius: 50%;
  background: color-mix(in srgb, var(--tone) 14%, #fff);
  color: var(--tone);
  font-size: 0.85rem;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--tone) 30%, #fff);
}

.ah-item--ok .ah-item__dot { --tone: var(--ah-ok); }
.ah-item--bad .ah-item__dot { --tone: var(--ah-bad); }
.ah-item--warn .ah-item__dot { --tone: var(--ah-warn); }
.ah-item--info .ah-item__dot { --tone: var(--ah-info); }
.ah-item--note .ah-item__dot { --tone: var(--ah-note); }
.ah-item--comment .ah-item__dot { --tone: var(--ah-comment); }

.ah-item__body {
  min-width: 0;
  padding: 0.55rem 0.75rem 0.6rem;
  border: 1px solid var(--ah-line);
  border-radius: 10px;
  background: #fff;
}

.ah-item__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.ah-item__title {
  color: var(--ah-ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.ah-item__time {
  flex: 0 0 auto;
  color: var(--ah-faint);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.ah-item__change {
  margin: 0.15rem 0 0;
  color: var(--ah-muted);
  font-size: 0.8rem;
}

.ah-item__comment {
  margin: 0.35rem 0 0;
  color: #334155;
  font-size: 0.84rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ah-item__comment.is-bubble {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: var(--ah-soft);
}

.ah-item--note .ah-item__comment.is-bubble {
  background: #f5f3ff;
}

.ah-item__file {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.35rem;
  font-size: 0.8rem;
}

.ah-item__by {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
  margin: 0.4rem 0 0;
  font-size: 0.76rem;
}

.ah-item__name {
  color: var(--ah-ink);
  font-weight: 600;
}

.ah-item__ticket {
  margin-left: auto;
  font-weight: 600;
}

.ah-actor {
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ah-actor--staff { background: #eef2ff; color: #3730a3; }
.ah-actor--user { background: #f0fdfa; color: #115e59; }
.ah-actor--system { background: #f1f5f9; color: #475569; }

/* ---------- Activity page feed ---------- */
.ahf-page {
  max-width: none;
}

.ahf-filters-panel .admin-desk-panel__body {
  padding: 1rem 1.15rem 0.9rem;
}

.ahf-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 0.85rem;
  align-items: end;
}

@media (min-width: 992px) {
  .ahf-filters {
    grid-template-columns: 11rem 12rem minmax(12rem, 1.4fr) 9.5rem 9.5rem auto;
  }
}

.ahf-filters__field .form-label,
.ahf-filters .form-label {
  margin-bottom: 0.3rem;
  color: var(--ah-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ahf-filters__field .form-select,
.ahf-filters__field .form-control {
  min-height: 2.25rem;
}

.ahf-filters__actions {
  display: flex;
  align-items: end;
}

.ahf-filters__submit {
  min-width: 5.5rem;
  min-height: 2.25rem;
  font-weight: 700;
}

.ahf-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.85rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--ah-line);
  color: var(--ah-muted);
  font-size: 0.82rem;
}

.ahf-meta__clear {
  font-weight: 600;
  text-decoration: none;
}

.ahf-meta__clear:hover {
  text-decoration: underline;
}

.ahf-alert {
  margin-bottom: 0.9rem;
}

.ahf-feed-panel {
  overflow: hidden;
}

.ahf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.ahf-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--ah-line);
  border-radius: 999px;
  background: #fff;
  color: var(--ah-muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ahf-chip:hover {
  border-color: #cbd5e1;
  color: var(--ah-ink);
}

.ahf-chip.is-active {
  border-color: #0f172a;
  background: #0f172a;
  color: #fff;
  box-shadow: none;
}

.ahf-chip .bi {
  font-size: 0.92rem;
  opacity: 0.9;
}

.ahf-day {
  padding: 0.6rem 1.1rem;
  border-bottom: 1px solid var(--ah-line);
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  color: var(--ah-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ahf-row {
  display: grid;
  grid-template-columns: 4.75rem 2rem minmax(0, 1.05fr) minmax(0, 1.7fr) auto;
  align-items: start;
  gap: 0.8rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--ah-line);
}

.ahf-row:hover {
  background: #fcfdfe;
}

.ahf-row__time {
  padding-top: 0.35rem;
  color: var(--ah-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ahf-row .ah-item__dot {
  border-color: transparent;
}

.ahf-row__subject {
  min-width: 0;
}

.ahf-row__kind {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--ah-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ahf-row__name {
  display: block;
  overflow: hidden;
  margin-top: 0.15rem;
  color: var(--ah-ink);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.ahf-row__name:hover {
  text-decoration: underline;
}

.ahf-row__what {
  min-width: 0;
}

.ahf-row__what .ah-item__title {
  font-size: 0.92rem;
}

.ahf-row__what .ah-item__comment {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.ahf-row__what .ah-item__by {
  margin-top: 0.35rem;
}

.ahf-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  color: var(--ah-muted);
  font-size: 0.82rem;
  background: #fff;
}

@media (max-width: 991.98px) {
  .ahf-row {
    grid-template-columns: 2rem minmax(0, 1fr) auto;
  }

  .ahf-row__time {
    grid-column: 2 / 3;
    grid-row: 1;
    padding-top: 0;
  }

  .ahf-row .ah-item__dot {
    grid-column: 1;
    grid-row: 1 / span 3;
  }

  .ahf-row__subject,
  .ahf-row__what {
    grid-column: 2 / 3;
  }

  .ahf-row > .ah-open {
    grid-column: 3;
    grid-row: 1;
  }
}
