/* ============================================================
   CareWheel Hub — styles page Historique
   ============================================================ */

#history-root {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Actions d'en-tête page Historique (bouton rafraîchir manuel) */
.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.history-refresh-btn {
  white-space: nowrap;
}

.history-filters {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.history-filter-entity {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.history-filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.history-filter-group-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.55;
  padding-left: 0.1rem;
}

.history-filter-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

@media (min-width: 720px) {
  .history-filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0;
  }

  .history-filter-entity {
    width: 100%;
    margin-bottom: 0.25rem;
  }

  .history-filter-group + .history-filter-group {
    border-left: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.12));
    padding-left: 0.85rem;
    margin-left: 0.85rem;
  }
}

.history-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.12));
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.history-filter-chip.is-active {
  border-color: var(--accent, #00ff96);
  background: rgba(0, 255, 150, 0.08);
}

.history-filter-chip--entity span[aria-hidden="true"] {
  opacity: 0.75;
  font-size: 1.1em;
  line-height: 1;
}

.history-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  overflow: hidden;
}

.history-table-head,
.history-table-row {
  display: grid;
  grid-template-columns: 9.5rem 5.5rem 5.5rem minmax(6rem, 1fr) minmax(8rem, 1.5fr) 7.5rem;
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem 0.75rem;
}

.history-table-row-wrap {
  border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
}

.history-table-row-wrap:last-child {
  border-bottom: none;
}

.history-table-row {
  border-bottom: none;
}

.history-table-head {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.65;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
}

.history-table-row {
  font-size: 0.85rem;
}

.history-table-row-wrap:last-child .history-table-row {
  border-bottom: none;
}

.history-table-row-wrap:hover .history-table-row {
  background: rgba(255, 255, 255, 0.02);
}

.history-col--category,
.history-col--entity,
.history-col--desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-col--desc {
  white-space: normal;
}

.history-desc-inner {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.history-desc-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.history-detail-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.15));
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.75;
}

.history-detail-toggle:hover {
  opacity: 1;
  border-color: var(--accent, #00ff96);
}

.history-detail-toggle.is-expanded .history-detail-chevron {
  transform: rotate(180deg);
}

.history-detail-chevron {
  width: 0.9rem;
  height: 0.9rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s ease;
}

.history-table-row-detail {
  padding: 0 0.75rem 0.55rem 0.75rem;
  font-size: 0.78rem;
  opacity: 0.88;
}

.history-table-row-detail[hidden] {
  display: none;
}

.history-detail-list {
  margin: 0;
  padding: 0.35rem 0 0.15rem 1.1rem;
  list-style: disc;
}

.history-detail-list li + li {
  margin-top: 0.2rem;
}

.history-entity-link {
  display: inline;
  max-width: 100%;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent, #00ff96);
  font: inherit;
  font-size: inherit;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-entity-link:hover {
  opacity: 0.85;
}

.animal-panel.is-history-focus,
.enclosure-panel.is-history-focus {
  outline: 2px solid var(--accent, #00ff96);
  outline-offset: 2px;
  border-radius: 12px;
}

.history-col--time {
  white-space: nowrap;
}

.history-col--actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  justify-content: flex-end;
  min-width: 7.5rem;
  max-width: 7.5rem;
  flex-shrink: 0;
}

.history-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.15));
  background: transparent;
  color: inherit;
  cursor: pointer;
  flex-shrink: 0;
}

.history-icon-btn svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-icon-btn:hover {
  border-color: var(--accent, #00ff96);
  background: rgba(0, 255, 150, 0.06);
}

.history-icon-btn--danger {
  border-color: rgba(255, 70, 100, 0.45);
  color: #ff8aa0;
}

.history-icon-btn--danger:hover {
  border-color: #ff8aa0;
  background: rgba(255, 70, 100, 0.08);
}

.history-level--action { color: #00ff96; }
.history-level--critical { color: #ff8aa0; }
.history-level--warning { color: #ffc266; }
.history-level--info { color: #8ec5ff; }
.history-level--neutral { opacity: 0.75; }

.history-empty,
.history-loading,
.history-error {
  padding: 2rem 1rem;
  text-align: center;
  opacity: 0.8;
}

.history-error {
  color: #ff8aa0;
}

.history-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.history-modal[hidden] {
  display: none;
}

.history-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.history-modal-panel {
  position: relative;
  width: min(100%, 28rem);
  background: var(--card-bg, #1a1f28);
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.12));
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.history-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.5rem;
}

.history-modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.history-modal-close {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}

.history-modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 1rem 1rem;
}

.history-modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.history-modal-field input,
.history-modal-field select {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--card-border, rgba(255, 255, 255, 0.15));
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  color-scheme: dark;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.history-modal-field input:focus,
.history-modal-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.history-modal-field select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a8fa8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  padding-right: 2rem;
  cursor: pointer;
}

.history-modal-field input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.75;
  filter: invert(0.85);
}

.history-modal-field select option {
  color: var(--text);
  background: var(--bg-elevated);
}

.history-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}

@media (max-width: 900px) {
  .history-table {
    overflow-x: auto;
  }

  .history-table-head,
  .history-table-row {
    min-width: 46rem;
  }
}

@media (max-width: 640px) {
  .animal-card-footer-actions {
    flex-wrap: wrap;
  }
}
