/* Widgets: data table, bar chart, dropdown menu, dialog, toast, checklist.
 * See static/README.md for the markup each one expects. */

/* --- data table ------------------------------------------------------------------- */

.table-card {
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.table-wrap {
  position: relative; /* keeps absolutely positioned .sr-only text inside the scroller */
  width: 100%;
  overflow-x: auto;
}

.table-toolbar .select {
  width: auto;
  min-width: 150px;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.table th {
  height: 38px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.table td {
  height: 56px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover td {
  background: var(--surface-2);
}

.table .col-num {
  text-align: right;
}

.table .col-actions {
  width: 52px;
  padding-right: 12px;
  text-align: right;
}

.table-compact td {
  height: 44px;
}

.table .col-end {
  text-align: right;
  white-space: nowrap;
}

.table .col-end form {
  display: inline;
}

@media (max-width: 760px) {
  .table .col-hide-md {
    display: none;
  }

  .table th,
  .table td {
    padding-left: 12px;
    padding-right: 12px;
  }

  .table .spark {
    display: none;
  }

  .table .cell-main {
    max-width: 44vw;
  }

  .table .col-actions {
    width: 40px;
    padding-left: 0;
    padding-right: 8px;
  }
}

@media (max-width: 480px) {
  .table .col-hide-sm {
    display: none;
  }

  .table-compact th,
  .table-compact td {
    padding-left: 8px;
    padding-right: 8px;
  }
}

/* The other half of col-hide-*: content that only shows once its column is gone. */
.show-below-md,
.show-below-sm {
  display: none;
}

@media (max-width: 760px) {
  .show-below-md {
    display: block;
  }
}

@media (max-width: 480px) {
  .show-below-sm {
    display: block;
    margin-top: 2px;
  }
}

.break {
  overflow-wrap: anywhere;
}

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 -6px;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.th-sort:hover {
  background: var(--surface-3);
  color: var(--text);
}

.th-sort .icon {
  width: 13px;
  height: 13px;
  opacity: 0.55;
}

th[aria-sort="ascending"] .th-sort,
th[aria-sort="descending"] .th-sort {
  color: var(--text);
}

th[aria-sort] .th-sort .icon {
  opacity: 1;
}

.table-empty {
  padding: 32px 16px;
  color: var(--text-2);
  text-align: center;
}

.table-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12.5px;
}

/* the first cell of a pages row: title over address */
.cell-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  max-width: 420px;
}

.cell-title {
  color: var(--text);
  font-weight: 500;
}

.cell-title:hover {
  color: var(--link);
}

.cell-sub {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--text-3);
  font-size: 12.5px;
}

.cell-sub a {
  color: inherit;
}

.cell-sub a:hover {
  color: var(--link);
}

.cell-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
}

/* --- bar chart -------------------------------------------------------------------- */

.bars {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 10px;
  height: 240px;
  padding-bottom: 22px;
}

.bars-y {
  position: relative;
  min-width: 24px;
  color: var(--text-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.bars-y span {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  line-height: 1;
}

.bars-plot {
  position: relative;
}

.bars-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.bars-x {
  position: absolute;
  right: 0;
  bottom: -22px;
  left: 0;
  height: 16px;
  color: var(--text-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.bars-x span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.chart-grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  shape-rendering: crispEdges;
}

.chart-hit {
  fill: transparent;
}

.chart-col:hover .chart-hit {
  fill: var(--surface-3);
}

.chart-bar-page {
  fill: var(--chart-1);
}

.chart-bar-embed {
  fill: var(--chart-2);
  /* a hairline of background between the two stacked series */
  stroke: var(--surface);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.disclosure-plain > summary {
  list-style: none;
}

.disclosure-plain > summary::-webkit-details-marker {
  display: none;
}

.disclosure-plain[open] > summary {
  margin-bottom: 8px;
}

@media (max-width: 600px) {
  .bars {
    height: 180px;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--text-2);
  font-size: 12.5px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--chart-1);
}

.legend-swatch-embed {
  background: var(--chart-2);
}

/* --- dropdown menu (a <details>; menu.js adds the keyboard) ----------------------- */

.menu {
  position: relative;
  display: inline-block;
}

.menu > summary {
  list-style: none;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.menu-up .menu-panel {
  top: auto;
  bottom: calc(100% + 4px);
}

/* Without JavaScript nothing can place the panel outside its scroll box (a table's
   .table-wrap scrolls, and would clip it), so it opens in normal flow instead and the
   row grows to hold it. menu.js positions it with position: fixed otherwise. */
html:not(.js) .menu-panel {
  position: static;
  margin-top: 4px;
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.menu-left .menu-panel {
  right: auto;
  left: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: 13.5px;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.menu-item .icon {
  color: var(--text-3);
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-3);
  outline: none;
  text-decoration: none;
}

.menu-item-danger,
.menu-item-danger .icon {
  color: var(--danger);
}

.menu-item-danger:hover,
.menu-item-danger:focus-visible {
  background: var(--danger-bg);
}

.menu-sep {
  height: 1px;
  margin: 4px -4px;
  background: var(--border);
}

.menu-label {
  padding: 6px 8px 4px;
  color: var(--text-3);
  font-size: 12px;
}

.menu form {
  margin: 0;
}

/* A confirm step: a <details> that works without JS; dialog.js lifts its body into
   the shared <dialog> instead. */
.confirm > summary {
  list-style: none;
}

.confirm > summary::-webkit-details-marker {
  display: none;
}

.confirm-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--surface);
  white-space: normal;
}

.confirm-body-plain {
  border-color: var(--border);
}

.menu .confirm-body {
  width: 300px;
}

/* --- dialog ----------------------------------------------------------------------- */

.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background: var(--overlay);
}

.dialog[open] {
  animation: dialog-in 0.14s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 20px 16px;
}

.dialog .confirm-body {
  margin: 0;
  padding: 0;
  border: 0;
}

.dialog-title {
  font-size: 16px;
  font-weight: 600;
}

.dialog-text {
  color: var(--text-2);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.dialog .confirm-actions {
  margin: 4px -20px -16px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-actions form {
  display: contents;
}

/* --- toast ------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

.toast .icon {
  margin-top: 1px;
}

.toast-ok .toast-icon {
  color: var(--ok-dot);
}

.toast-warn .toast-icon {
  color: var(--warn-dot);
}

.toast-error .toast-icon {
  color: var(--danger-dot);
}

.toast-text {
  flex: 1;
  min-width: 0;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 600px) {
  .toasts {
    right: 16px;
    bottom: 16px;
    left: 16px;
    width: auto;
  }
}

/* --- onboarding checklist --------------------------------------------------------- */

.checklist {
  display: flex;
  flex-direction: column;
  counter-reset: step;
  padding: 0;
  list-style: none;
}

.checklist-item {
  display: flex;
  gap: 14px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.checklist-item:first-child {
  border-top: 0;
}

.checklist-num {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.checklist-item.is-next .checklist-num {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
}

.checklist-main {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  min-width: 0;
}

.checklist-title {
  font-weight: 500;
}

.checklist-desc {
  margin-top: 2px;
  color: var(--text-2);
  font-size: 13px;
}

/* --- share bar (a meter with its percentage) --------------------------------------- */

.share {
  display: grid;
  grid-template-columns: minmax(60px, 160px) 40px;
  align-items: center;
  gap: 10px;
}

/* --- a Pro-gated feature ---------------------------------------------------------- */

.locked-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 20px;
}

.locked-body .empty-icon {
  margin: 0;
}

.locked-text {
  flex: 1;
  min-width: 240px;
}
