/* Tables inside bg-base-200 cards: use base-100 for visible zebra contrast */
.card-table tbody tr:nth-child(2n) {
  background-color: var(--color-base-100);
}

/* Reduced-motion spinner support lives in base.css: .loading-spinner is a
   global daisyui class (me.html, ingest) and this file only loads on
   /visualize pages. */

.viz-card {
  position: relative;
  overflow: visible;
  border-radius: 16px;
  border: none;
  isolation: isolate;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}
.viz-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, #a855f7, #6366f1 45%, #14b8a6);
  filter: blur(0);
  opacity: 0;
  transition:
    opacity 0.35s ease,
    filter 0.35s ease;
  z-index: 0;
  pointer-events: none;
  will-change: opacity, filter, transform;
  transform: scale(1);
}
.viz-card::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  /*background: rgba(255, 255, 255, 0.92);*/
  background-color: var(--color-base-200);
  z-index: 1;
  pointer-events: none;
}
.viz-card:hover::before {
  opacity: 0.6;
  filter: blur(20px);
  transform: scale(1.03);
}
[data-theme="dark"] .viz-card::before {
  background: linear-gradient(135deg, #22d3ee, #8b5cf6 45%, #22c55e);
}
[data-theme="dark"] .viz-card::after {
  background: rgba(17, 24, 39, 0.94);
}
.viz-card > .card-body {
  position: relative;
  z-index: 2;
}

/* Safari/WebKit: blur animations on pseudo-elements can flicker and smear. */
@supports (-webkit-touch-callout: none) {
  .viz-card::before {
    filter: none;
    -webkit-filter: none;
    transition:
      opacity 0.28s ease,
      transform 0.28s ease;
    transform: scale(0.98);
  }

  .viz-card:hover::before {
    opacity: 0.4;
    transform: scale(1.015);
    filter: none;
    -webkit-filter: none;
  }
}

/* ─── Subscriptions page ─────────────────────────────────────────────────── */

.subscriptions-table-wrap {
  overflow-x: auto;
  border-radius: 0.75rem;
  border: 1px solid var(--color-base-300, #d1d5db);
}

/* Rows come in pairs: data-row (odd pos) + sub-entries-row (even pos).
   Cancel DaisyUI zebra (which stripes even = sub-entries-rows), then
   stripe every other DATA row: positions 1,5,9... = 4n+1. */
.subscriptions-table tbody tr:nth-child(even) {
  background: transparent;
}

.subscriptions-table tbody tr:nth-child(4n + 1) {
  background: var(--color-base-200, #f3f4f6);
}

/* sub-entries row keeps its own distinct background, overrides everything */
.subscriptions-table tbody tr.sub-entries-row {
  background: color-mix(
    in oklab,
    var(--color-base-200) 35%,
    transparent
  ) !important;
}

.subscriptions-table .subscriptions-number,
.subscriptions-table .subscriptions-action {
  text-align: right;
  white-space: nowrap;
}

.subscriptions-table .subscriptions-name {
  font-weight: 600;
}

.subscriptions-table .subscriptions-name-cell {
  white-space: nowrap;
  max-width: 220px;
}

.sub-name-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.sub-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.subscriptions-table .subscriptions-secondary {
  color: color-mix(
    in oklab,
    var(--color-base-content, #111827) 68%,
    transparent
  );
  white-space: nowrap;
}

.subscriptions-table .subscriptions-negative {
  color: var(--color-error, #dc2626);
}

.subscriptions-summary .stat-title {
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}

.subscriptions-summary .stat-value {
  font-size: 1.6rem;
  line-height: 1.15;
}

.subscriptions-summary .stat-desc {
  font-size: 0.8rem;
}

.subscriptions-mobile-list {
  flex-direction: column;
  gap: 0.75rem;
}

.subscriptions-mobile-only {
  display: none;
}

.subscriptions-desktop-only {
  display: block;
}

.subscriptions-card {
  border: 1px solid var(--color-base-300, #d1d5db);
  border-radius: 1rem;
  background: var(--color-base-100, #ffffff);
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.subscriptions-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.875rem;
}

.subscriptions-card-name {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.subscriptions-card-amount {
  flex: 0 0 auto;
}

.subscriptions-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.875rem;
}

.subscriptions-card-item dt {
  margin-bottom: 0.2rem;
  color: color-mix(
    in oklab,
    var(--color-base-content, #111827) 60%,
    transparent
  );
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.subscriptions-card-item dd {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.35;
}

.sub-badge {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.sub-badge-stable {
  background: color-mix(
    in oklab,
    var(--color-success, #16a34a) 15%,
    transparent
  );
  color: var(--color-success, #16a34a);
}

.sub-badge-changed {
  background: color-mix(
    in oklab,
    var(--color-warning, #d97706) 15%,
    transparent
  );
  color: var(--color-warning, #d97706);
}

.sub-badge-irregular {
  background: color-mix(in oklab, var(--color-error, #dc2626) 12%, transparent);
  color: var(--color-error, #dc2626);
}

.sub-exclude-btn {
  font-size: 0.72rem;
  opacity: 0.45;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.25rem;
  line-height: 1;
}

.sub-exclude-btn:hover {
  opacity: 1;
}

.sub-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.5;
  padding: 0.15rem 0.3rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  transition:
    opacity 0.1s,
    transform 0.15s;
}

.sub-expand-btn:hover {
  opacity: 1;
}

.sub-expand-btn--open {
  transform: rotate(90deg);
}

.sub-entries-row td {
  padding: 0 !important;
  background: color-mix(in oklab, var(--color-base-200) 35%, transparent);
  border-left: 3px solid
    color-mix(in oklab, var(--color-base-300) 80%, transparent);
}

.sub-entries-loading {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: color-mix(in oklab, var(--color-base-content) 50%, transparent);
}

.sub-entries-list {
  display: flex;
  flex-direction: column;
  padding-left: 1.5rem;
}

.sub-entry-item {
  display: grid;
  grid-template-columns: 7rem 7rem 1fr;
  gap: 0 1.25rem;
  align-items: baseline;
  padding: 0.55rem 1.25rem;
  font-size: 0.84rem;
}

.sub-entry-even {
  background: transparent;
}

.sub-entry-odd {
  background: color-mix(in oklab, var(--color-base-200) 45%, transparent);
}

.sub-entry-outlier {
  background: color-mix(in oklab, var(--color-warning) 12%, transparent);
  border-left: 3px solid var(--color-warning, #d97706);
  padding-left: calc(1.25rem - 3px);
}

.sub-entry-date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: color-mix(in oklab, var(--color-base-content) 55%, transparent);
}

.sub-entry-amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.sub-entry-negative {
  color: var(--color-error, #dc2626);
}
.sub-entry-positive {
  color: var(--color-success, #16a34a);
}

.sub-entry-outlier .sub-entry-negative,
.sub-entry-outlier .sub-entry-positive {
  font-weight: 700;
}

.sub-entries-meta-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.45rem 1.25rem;
  border-bottom: 1px solid
    color-mix(in oklab, var(--color-base-300) 60%, transparent);
}

.sub-entry-desc {
  color: color-mix(in oklab, var(--color-base-content) 65%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}

.sub-entry-meta-chip {
  font-size: 0.68rem;
  padding: 0.1em 0.45em;
  border-radius: 4px;
  background: color-mix(in oklab, var(--color-base-300) 60%, transparent);
  color: color-mix(in oklab, var(--color-base-content) 60%, transparent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sub-entries-empty {
  padding: 0.6rem 1.25rem;
  font-size: 0.84rem;
  color: color-mix(in oklab, var(--color-base-content) 45%, transparent);
}

.sub-contract-hint {
  font-size: 0.72rem;
  font-weight: 400;
  color: color-mix(in oklab, var(--color-base-content) 45%, transparent);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.sub-excluded-section summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: color-mix(in oklab, var(--color-base-content) 50%, transparent);
  padding: 0.5rem 0;
}

.sub-excluded-section summary::-webkit-details-marker {
  display: none;
}

.sub-excluded-section summary::before {
  content: "▶";
  font-size: 0.65rem;
  transition: transform 0.15s;
}

.sub-excluded-section[open] summary::before {
  transform: rotate(90deg);
}

/* Row actions: rename, merge, exclude */
.sub-row-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  position: relative;
}

.sub-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 0.3rem;
  opacity: 0.45;
  transition:
    opacity 0.15s,
    background 0.15s;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

.sub-action-btn:hover {
  opacity: 1;
  background: color-mix(in oklab, var(--color-base-200) 70%, transparent);
}

.sub-rename-form {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.2rem;
}

.sub-rename-input {
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--color-base-300, #d1d5db);
  border-radius: 0.4rem;
  font-size: 0.85rem;
  background: var(--color-base-100);
  color: var(--color-base-content);
  min-width: 10rem;
}

.sub-rename-save {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-success, #16a34a);
  padding: 0.1rem 0.3rem;
  display: inline-flex;
  align-items: center;
}

.sub-merge-panel {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 50;
  background: var(--color-base-100, #fff);
  border: 1px solid var(--color-base-300, #d1d5db);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.sub-merge-select {
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--color-base-300, #d1d5db);
  border-radius: 0.4rem;
  font-size: 0.85rem;
  background: var(--color-base-100);
  color: var(--color-base-content);
  max-width: 14rem;
}

.sub-merge-confirm {
  padding: 0.25rem 0.6rem;
  background: var(--color-primary, #6366f1);
  color: var(--color-primary-content, #fff);
  border: none;
  border-radius: 0.4rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.sub-merge-confirm:hover {
  opacity: 0.85;
}

.sub-threshold-control {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: flex-end;
}

.sub-threshold-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: color-mix(in oklab, var(--color-base-content) 55%, transparent);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* <details> tooltip: tap on mobile, hover on desktop */
.sub-threshold-hint {
  font-size: 0.85rem;
  opacity: 0.6;
  position: relative;
  display: inline-flex;
  align-items: center;
}

.sub-threshold-hint summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.sub-threshold-hint summary::-webkit-details-marker {
  display: none;
}

/* show on tap (open state) or hover */
.sub-threshold-hint[open] .sub-threshold-tooltip,
.sub-threshold-hint:hover .sub-threshold-tooltip {
  display: block;
}

.sub-threshold-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  width: 16rem;
  background: var(--color-base-300, #e5e7eb);
  color: var(--color-base-content);
  font-size: 0.78rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.4;
  padding: 0.5rem 0.65rem;
  border-radius: 0.4rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 100;
  white-space: normal;
}

.sub-threshold-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sub-threshold-input {
  width: 6rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-base-300, #d1d5db);
  border-radius: 0.5rem;
  background: var(--color-base-100, #fff);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--color-base-content);
}

.sub-threshold-input:focus {
  outline: 2px solid var(--color-primary, #6366f1);
  outline-offset: 1px;
}

.sub-threshold-unit {
  font-size: 0.9rem;
  color: color-mix(in oklab, var(--color-base-content) 55%, transparent);
}

@media (max-width: 639px) {
  .subscriptions-mobile-only {
    display: flex;
  }

  .subscriptions-desktop-only {
    display: none;
  }

  .sub-threshold-control {
    align-items: flex-start;
  }
}
