/* Planet positions table (js/positions/positions-table.js): the last section of the Charts tab, and anywhere else it is
   mounted (chat cards, landing pages). Layout follows the table's own width (container queries). The table is wide, so it
   always sits in a sideways-scrolling box with # and Planet kept in view. */

.positions-view { container: positions / inline-size; display: grid; gap: 10px; min-width: 0; }
.positions-view[aria-busy="true"] .positions-status > span { animation: positions-pulse 1.2s ease-in-out infinite; }
@keyframes positions-pulse { 50% { opacity: .35; } }

/* 1. Toolbar: dropdown, then the column toggles -------------------------------------------------------------------- */
.positions-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 18px; }
.positions-field { display: grid; gap: 5px; min-width: 0; }
.positions-label { color: var(--gold-label); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.positions-select {
  min-width: 210px;
  min-height: 34px;
  padding: 0 32px 0 11px;
  border: 1px solid var(--gold-border);
  border-radius: 10px;
  background: #fffefa url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237a6726' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 11px center / 10px 6px;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  appearance: none;
  cursor: pointer;
}
.positions-select:hover { border-color: var(--gold-border-strong); }
.positions-select:focus-visible { outline: 2px solid #b39a30; outline-offset: 1px; }
.positions-group-toggle button { white-space: nowrap; }

/* 2. Status line and hint ------------------------------------------------------------------------------------------ */
.positions-status { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 14px; color: #8b867c; font-size: 11px; }
.positions-status > span { color: #b39a30; font-size: 14px; }
.positions-status[hidden], .positions-hint[hidden], .positions-scroll[hidden], .positions-legend[hidden] { display: none; }
.positions-hint { display: none; margin: 0 0 -4px; color: #8b867c; font-size: 10px; text-align: right; }

/* 3. The table ----------------------------------------------------------------------------------------------------- */
.positions-scroll {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--gold-border);
  border-radius: 14px;
  background: #fffefa;
  box-shadow: var(--surface-paper-shadow);
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #e1d09b transparent;
  scrollbar-width: thin;
}
.positions-scroll:focus-visible { outline: 2px solid #b39a30; outline-offset: 2px; }
.positions-table {
  /* Group colours (header accents); the cells' own colours follow below. */
  --pos-core: #252523;
  --pos-green: var(--green, #6c9b78);
  --pos-gold: var(--yellow-deep, #e5bf39);
  --pos-blue: var(--blue, #7491bd);
  --pos-rose: var(--rose, #ce7b78);
  --pos-sno-width: 36px;
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ink);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.positions-caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.positions-table th,
.positions-table td { padding: 7px 10px; border-bottom: 1px solid var(--gold-line); background: #fffefa; text-align: left; vertical-align: middle; white-space: nowrap; }
.positions-table tbody tr:nth-child(even) > * { background: #fffbf0; }
/* Rows: hover tints the whole row; a click marks it (stays until clicked again), any number at once.
   Colours are opaque so the pinned # / Planet cells match the rest of the row. */
.positions-table tbody tr { cursor: pointer; transition: none; }
.positions-table tbody tr > * { transition: background-color .12s ease; }
.positions-table tbody tr:hover > * { background: #fdf0c4; }
.positions-table tbody tr.is-selected > * { background: #f7dc7c; border-bottom-color: #ead08a; }
.positions-table tbody tr.is-selected:hover > * { background: #f3d264; }
.positions-table tbody tr.is-selected > :first-child { box-shadow: inset 4px 0 0 #b39a30; }
.positions-table tbody tr.is-selected [data-col="sno"] { color: #252523; font-weight: 800; }
.positions-table tbody tr:focus-visible { outline: none; }
.positions-table tbody tr:focus-visible > * { box-shadow: inset 0 2px 0 #b39a30, inset 0 -2px 0 #b39a30; }
.positions-table tbody tr.is-selected:focus-visible > :first-child { box-shadow: inset 4px 0 0 #b39a30, inset 0 2px 0 #b39a30, inset 0 -2px 0 #b39a30; }
@media (prefers-reduced-motion: reduce) { .positions-table tbody tr > * { transition: none; } }
.positions-table tbody tr:last-child > * { border-bottom: 0; }
.positions-table .pos-group-start { border-left: 1px solid var(--gold-line); }

/* Header row 1 (group names): a dark band with gold text and a coloured line per group. */
.positions-group-row th {
  padding: 6px 10px 5px;
  border-bottom: 0;
  background: #252523;
  color: var(--yellow, #f5d653);
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  box-shadow: inset 0 -3px 0 var(--pos-accent, var(--pos-gold));
}
.positions-group-row th.pos-group-start { border-left-color: #3d3a2e; }
/* Header row 2 (column names). */
.positions-column-row th {
  padding: 7px 10px;
  background: var(--gold-50, #fffbef);
  color: var(--gold-ink, #7a6726);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.positions-column-row th[title] { cursor: help; }
.positions-table [data-tone="core"] { --pos-accent: var(--pos-gold); }
.positions-table [data-tone="green"] { --pos-accent: var(--pos-green); }
.positions-table [data-tone="gold"] { --pos-accent: var(--pos-gold); }
.positions-table [data-tone="blue"] { --pos-accent: var(--pos-blue); }
.positions-table [data-tone="rose"] { --pos-accent: var(--pos-rose); }

/* # and Planet stay in view while the rest scrolls. */
.positions-table .pos-sticky { position: sticky; z-index: 1; }
.positions-table [data-col="sno"] { left: 0; box-sizing: border-box; padding-inline: 4px; width: var(--pos-sno-width); min-width: var(--pos-sno-width); max-width: var(--pos-sno-width); color: #8b867c; text-align: center; }
.positions-table [data-col="planet"] { left: var(--pos-sno-width); box-shadow: inset -1px 0 0 var(--gold-line), 6px 0 8px -8px rgb(37 37 35 / 35%); }
.positions-table .pos-sticky--corner { left: 0; z-index: 2; }
.positions-table thead .pos-sticky { z-index: 2; }

/* 4. Cells --------------------------------------------------------------------------------------------------------- */
.pos-empty { color: #c2bcae; }
.pos-degree { font-weight: 700; letter-spacing: -.01em; }
.pos-sign[title], .pos-planet[title], .pos-code[title], .pos-amsa[title] { cursor: help; }
.pos-planet { display: inline-flex; align-items: baseline; gap: 4px; color: var(--pos-planet, var(--ink)); font-weight: 800; }
.pos-planet-glyph { min-width: 1em; font-size: 12px; font-weight: 400; text-align: center; }
.pos-planet[data-planet="Sun"] { --pos-planet: #c4620f; }
.pos-planet[data-planet="Moo"] { --pos-planet: #2c52b0; }
.pos-planet[data-planet="Mar"] { --pos-planet: #cf4418; }
.pos-planet[data-planet="Mer"] { --pos-planet: #2c7a43; }
.pos-planet[data-planet="Jup"] { --pos-planet: #c0820a; }
.pos-planet[data-planet="Ven"] { --pos-planet: #18807f; }
.pos-planet[data-planet="Sat"] { --pos-planet: #252523; }
.pos-planet[data-planet="Rah"] { --pos-planet: #262f6b; }
.pos-planet[data-planet="Ket"] { --pos-planet: #8a3a20; }
.pos-planet-list { display: inline-flex; flex-wrap: nowrap; gap: 4px; }
.pos-planet--chip { padding: 1px 6px 1px 4px; border: 1px solid var(--gold-line); border-radius: 999px; background: #fffefa; font-size: 10.5px; }
.pos-planet--chip .pos-planet-glyph { font-size: 10.5px; }

.pos-codes { display: inline-flex; flex-wrap: nowrap; gap: 3px; }
.pos-code {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 6px;
  background: #f1ede4;
  color: #5d594f;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
}
.pos-code[data-tone="good"] { background: #e6f0e8; color: #356543; }
.pos-code[data-tone="bad"] { background: #f8e6e4; color: #a24a45; }
.pos-code[data-tone="warn"] { background: #f5e8dc; color: #87542a; }

.pos-amsa { display: inline-flex; align-items: baseline; gap: 4px; font-weight: 750; }
.pos-amsa-part { color: #9a958c; font-size: 9.5px; font-weight: 700; }
.pos-amsa[data-tone="good"] .pos-amsa-name { color: #2c7a43; }
.pos-amsa[data-tone="good-soft"] .pos-amsa-name { color: #5c9c6b; }
.pos-amsa[data-tone="warn"] .pos-amsa-name { color: #c0607e; }
.pos-amsa[data-tone="bad"] .pos-amsa-name { color: #c23b30; }

/* 4b. Lead rows: the running dasha lords' positions above the table (transit desk). Not markable. */
.positions-lead { display: grid; gap: 6px; }
.positions-lead[hidden] { display: none; }
.positions-lead-title { margin: 0; color: var(--gold-label); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.positions-table--lead { --pos-sno-width: 66px; }
.positions-table--lead [data-col="level"] { left: 0; box-sizing: border-box; width: var(--pos-sno-width); min-width: var(--pos-sno-width); max-width: var(--pos-sno-width); color: var(--gold-ink); font-weight: 800; }
.positions-table--lead tbody tr { cursor: default; }
.positions-table--lead tbody tr[data-level="Antra"] > *,
.positions-table--lead tbody tr:hover > * { background: #fffefa; }
.positions-table--lead tbody tr[data-level="Dasha"] > * { background: #fff8e2; }

/* 5. Legend -------------------------------------------------------------------------------------------------------- */
.positions-legend { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--gold-line); border-radius: 12px; background: var(--surface-paper-bg); }
.positions-legend-line { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 12px; margin: 0; color: #5d594f; font-size: 10px; }
.positions-legend-title { color: var(--gold-label); font-size: 8.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.positions-legend-item { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* 6. Narrow (phones, chat cards): tighter cells, the sideways hint, the dropdown full width ------------------------ */
@container positions (max-width: 640px) {
  .positions-toolbar { display: grid; grid-template-columns: minmax(0, 1fr); }
  .positions-select { width: 100%; min-width: 0; }
  .positions-group-toggle { flex-wrap: nowrap; width: 100%; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .positions-group-toggle::-webkit-scrollbar { display: none; }
  .positions-hint:not([hidden]) { display: block; }
  .positions-table { --pos-sno-width: 28px; font-size: 11px; }
  .positions-table th, .positions-table td { padding: 6px 8px; }
  .positions-legend-line { font-size: 9.5px; }
}
@media (prefers-reduced-motion: reduce) { .positions-view[aria-busy="true"] .positions-status > span { animation: none; } }
