/* =============================================================================
   HOME (wireframe H, agreed 2 Nov 2026; Home class, home.js, api/home.php)

   1. The page: greeting and date, Edit home, Create ⌄
   2. The widget grid: 4 columns of 184px rows; small 1 column, medium 2, large 2 by 2
   3. A widget: its head (title, note, ⋯) and body
   4. What widgets hold: numbers, bars, lists, totals, set up, empty, error, loading
   5. Edit home: grip, sizes, hide, dragging; the Add widgets panel
   6. Phones: 2 columns, sheets, the edit list
   ============================================================================= */

.home {
  --home-chart: #3e7fe0;
  --home-chart-part: #a9c8f3;
  --home-chart-hover: #0b63c9;
  --home-late: #c81e1e;
  --home-now: var(--loon-item-selected-color, #0962bf);
  --home-edge: 1.5rem; /* inside a widget (cards elsewhere: --loon-space) */
  --home-gap: 1.5rem;

  display: flex;
  flex-direction: column;
  gap: var(--home-gap);
}

[data-bs-theme=dark] .home {
  --home-chart: #6ea2f0;
  --home-chart-part: #3a5f96;
  --home-chart-hover: #a9c8f3;
  --home-late: #f58b8b;
  --home-now: #8fbaf5;
}

/* Charts take the colour of their module's category (as its square in the menu, nav.css 9) */
.home-cat-people { --home-chart: #8b6be0; --home-chart-part: #d6c9f7; --home-chart-hover: #6d28d9; }
.home-cat-finance { --home-chart: #2e9e5b; --home-chart-part: #b9e3c9; --home-chart-hover: #15803d; }
.home-cat-operations { --home-chart: #1a9b8f; --home-chart-part: #b4e3de; --home-chart-hover: #0f766e; }
.home-cat-supply-chain { --home-chart: #d08a1e; --home-chart-part: #f5d9ab; --home-chart-hover: #b45309; }

.home [hidden],
.home-add[hidden] {
  display: none !important;
}


/* 1. THE PAGE ------------------------------------------------------------------ */

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.home-title {
  min-width: 0;
}

.home-hello {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
}

.home-date {
  margin: 0;
  color: var(--bs-fg-3);
  font-size: var(--bs-body-font-size-sm);
}

.home-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
}

.home-actions .btn {
  gap: 0.5rem;
}

.home-create {
  position: relative;
}

.home-caret {
  font-size: 0.75rem;
}

.home-edit-end {
  display: none;
}

.home-menu .menu-item .nav-square {
  width: 1.375rem;
  height: 1.375rem;
  font-size: 0.75rem;
}

.home-menu [data-home-size] .home-check {
  visibility: hidden;
}

.home-menu [data-home-size][aria-checked=true] .home-check {
  visibility: visible;
}

.home-empty-grid {
  margin: 0;
  padding: 2.5rem;
  border: 1.5px dashed var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  color: var(--bs-fg-3);
  text-align: center;
}

.home-nomodules {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 3rem var(--loon-space);
  text-align: center;
}

.home-nomodules h2 {
  margin: 0.25rem 0 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.home-nomodules p {
  margin: 0 0 0.5rem;
  color: var(--bs-fg-3);
}

.home-nomodules-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--bs-border-radius-lg);
  background: var(--loon-item-hover-bg);
  color: var(--bs-fg-2);
  font-size: 1.25rem;
}


/* 2. THE GRID ------------------------------------------------------------------ */

/* The user's order; a gap is filled by the next widget that fits (dense) */
.home-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 11.5rem;
  grid-auto-flow: dense;
  gap: var(--home-gap);
}

.home-w[data-size=m] {
  grid-column: span 2;
}

.home-w[data-size=l] {
  grid-column: span 2;
  grid-row: span 2;
}

@media (width < 1200px) {
  .home-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}


/* 3. A WIDGET ------------------------------------------------------------------ */

.card.home-w {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 1.125rem var(--home-edge);
}

.home-w-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
  margin-bottom: 0.625rem;
}

.home-w-title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-w-title a {
  color: inherit;
  text-decoration: none;
}

.home-w-title a:hover {
  color: var(--bs-link-color);
}

.home-w-note {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--bs-fg-3);
  font-size: 0.8125rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ⋯: while the widget is pointed at or has focus; faint on touch screens */
.home-w-more {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin: -0.25rem -0.5rem -0.25rem 0;
  padding: 0;
  border: 0;
  border-radius: var(--bs-border-radius);
  background: transparent;
  color: var(--bs-fg-3);
  opacity: 0;
}

.home-w:hover .home-w-more,
.home-w:focus-within .home-w-more,
.home-w-more.show {
  opacity: 1;
}

.home-w-more:hover,
.home-w-more.show {
  background: var(--loon-item-hover-bg);
  color: var(--bs-body-color);
}

@media (pointer: coarse) {
  .home-w-more {
    opacity: 0.6;
  }
}

.home-w-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.home-w-body[aria-busy=true] > :not(.home-sk) {
  opacity: 0.5;
}

.home-w .home-menu {
  min-width: 13rem;
}


/* 4. WHAT WIDGETS HOLD --------------------------------------------------------- */

.home-big {
  color: var(--bs-body-color);
  font-size: 1.875rem;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}

a.home-big:hover {
  color: var(--bs-link-color);
}

.home-up {
  color: var(--bs-success);
  font-size: 0.8125rem;
}

.home-muted {
  color: var(--bs-fg-3);
  font-size: 0.8125rem;
}

.home-late {
  color: var(--home-late) !important;
  font-weight: 500;
}

.home-now {
  color: var(--home-now) !important;
  font-weight: 500;
}

.home-link {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--bs-link-color);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover {
  text-decoration: underline;
}

/* A widget's link at its foot: See all 14, Open Billing */
.home-foot {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 0.375rem;
  margin-top: auto;
  padding: 0.5rem 0 0;
  border: 0;
  background: none;
  color: var(--bs-link-color);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

.home-foot:hover {
  text-decoration: underline;
}

/* Lists: a row from edge to edge, the name, what it is, when */
.home-rows {
  margin: 0 calc(var(--home-edge) * -1);
  padding: 0;
  list-style: none;
}

.home-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.875rem;
  padding: 0 var(--home-edge);
  border-top: 1px solid var(--bs-border-color-translucent);
}

.home-rows-tight {
  margin: 0;
}

.home-row-tight {
  gap: 0.625rem;
  min-height: 2rem;
  padding: 0;
  border-top: 0;
}

.home-rows-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1rem;
}

.home-rows-all {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.home-row .nav-square {
  width: 1.375rem;
  height: 1.375rem;
  font-size: 0.75rem;
}

.home-row-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-row-name a {
  color: var(--bs-body-color);
  text-decoration: none;
}

.home-row-name a:hover {
  color: var(--bs-link-color);
}

.home-pill {
  flex: none;
  padding: 0.0625rem 0.5rem;
  border-radius: var(--bs-border-radius-pill);
  background: var(--loon-item-hover-bg);
  color: var(--bs-fg-2);
  font-size: 0.75rem;
  white-space: nowrap;
}

.home-w[data-size=s] .home-pill {
  display: none;
}

.home-when {
  flex: none;
  margin-left: auto;
  color: var(--bs-fg-3);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.home-time {
  flex: none;
  width: 2.75rem;
  color: var(--bs-fg-3);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

/* Added per month: bars on a baseline, the month under way paler; a tip on point or focus */
.home-bars {
  display: flex;
  flex: 1;
  align-items: flex-end;
  gap: 0.875rem;
  min-height: 0;
  padding: 0 0.25rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.home-w[data-size=l] .home-bars,
.home-w[data-size=l] .home-bar-labels {
  gap: 0.5rem;
}

.home-col {
  position: relative;
  display: flex;
  flex: 1;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  outline: none;
}

.home-col i {
  display: block;
  width: 100%;
  max-width: 2.75rem;
  border-radius: 4px 4px 0 0;
  background: var(--home-chart);
}

.home-col i.home-part {
  background: var(--home-chart-part);
}

.home-col:hover i,
.home-col:focus-visible i {
  background: var(--home-chart-hover);
}

.home-col[data-tip]:hover::after,
.home-col[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 3;
  padding: 0.375rem 0.625rem;
  border-radius: var(--bs-border-radius);
  background: #1f2937;
  color: #fff;
  font-size: 0.78125rem;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.home-col:first-child[data-tip]::after { left: 0; transform: none; }
.home-col:last-child[data-tip]::after { right: 0; left: auto; transform: none; }

.home-bar-labels {
  display: flex;
  gap: 0.875rem;
  padding: 0.25rem 0.25rem 0;
}

.home-bar-labels span {
  flex: 1;
  color: var(--bs-fg-3);
  font-size: 0.75rem;
  text-align: center;
}

/* Breakdown: a bar per value, longest = the most */
.home-hbars {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.home-hbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 1.5rem;
  font-size: 0.84375rem;
}

.home-hbar-label {
  flex: none;
  width: 6.5rem;
  overflow: hidden;
  color: var(--bs-fg-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-hbar-track {
  flex: 1;
  height: 0.75rem;
}

.home-hbar-track i {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--home-chart);
}

.home-hbar-value {
  flex: none;
  min-width: 6.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.home-hbar-value span {
  color: var(--bs-fg-3);
}

/* Total: the late part of the amount, in red, beside the rest */
.home-split {
  display: flex;
  gap: 2px;
  height: 0.625rem;
  margin: 0.75rem 0 0.5rem;
}

.home-split i {
  flex: 1;
  border-radius: 0 4px 4px 0;
  background: var(--bs-gray-300);
}

.home-split i.home-split-late {
  flex: none;
  border-radius: 4px 0 0 4px;
  background: var(--home-late);
}

.home-spark {
  display: block;
  width: 100%;
  height: 2.75rem;
  margin-top: auto;
}

.home-spark polyline {
  fill: none;
  stroke: var(--home-chart);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* Set up: done steps ticked and struck through; the next steps' links at their end */
.home-progress {
  display: block;
  height: 0.375rem;
  margin: 0.125rem 0 0.75rem;
  overflow: hidden;
  border-radius: var(--bs-border-radius-pill);
  background: var(--bs-gray-200);
}

.home-progress i {
  display: block;
  height: 100%;
  background: var(--bs-success);
}

.home-step-mark {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 1.125rem;
  height: 1.125rem;
  border: 1.5px solid var(--bs-gray-500);
  border-radius: 50%;
  color: #fff;
  font-size: 0.6875rem;
}

.home-step.is-done .home-step-mark {
  border: 0;
  background: var(--bs-success);
}

.home-step.is-done .home-row-name {
  color: var(--bs-fg-3);
  font-weight: 400;
  text-decoration: line-through;
}

.home-step .home-link {
  align-self: center;
  margin-left: auto;
}

/* Empty, error, loading */
.home-empty,
.home-error {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  color: var(--bs-fg-3);
  font-size: 0.84375rem;
}

.home-empty b {
  color: var(--bs-fg-1);
  font-size: 0.875rem;
  font-weight: 500;
}

.home-error {
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--bs-fg-2);
}

.home-sk {
  display: block;
  height: 0.625rem;
  margin: 0.5rem 0;
  border-radius: 4px;
  background: var(--bs-gray-200);
  animation: home-pulse 1.4s ease-in-out infinite;
}

.home-sk-s { width: 40%; }
.home-sk-m { width: 62%; }
.home-sk-l { width: 88%; }
.home-sk-big { width: 50%; height: 1.5rem; }

@keyframes home-pulse {
  50% { opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
  .home-sk { animation: none; }
}


/* 5. EDIT HOME ----------------------------------------------------------------- */

.card.home-editbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin: 0;
  padding: 0.875rem var(--home-edge);
}

.home-editbar-text {
  flex: 1 1 18rem;
  min-width: 0;
}

.home-editbar h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.home-editbar p {
  margin: 0;
  color: var(--bs-fg-3);
  font-size: var(--bs-body-font-size-sm);
}

.home-w-grip,
.home-w-sizes,
.home-w-hide {
  display: none;
}

.home.is-editing .home-w-grip {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.75rem;
  margin-left: -0.5rem;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--bs-fg-3);
  cursor: grab;
  touch-action: none;
}

.home.is-editing .home-w-grip:hover,
.home.is-editing .home-w-grip:focus-visible {
  background: var(--loon-item-hover-bg);
  color: var(--bs-body-color);
}

.home.is-editing .home-w-sizes {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  border-radius: var(--bs-border-radius);
  background: var(--bs-gray-200);
}

.home-w-sizes button {
  width: 1.625rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--bs-fg-2);
  font-size: 0.75rem;
  font-weight: 500;
}

.home-w-sizes button[aria-pressed=true] {
  background: var(--bs-component-bg);
  box-shadow: 0 0 0 1px var(--bs-gray-500);
  color: var(--bs-body-color);
}

.home.is-editing .home-w-hide {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.875rem;
  height: 1.875rem;
  padding: 0;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background: var(--bs-component-bg);
  color: var(--bs-fg-2);
}

.home.is-editing .home-w-hide:hover {
  color: var(--bs-body-color);
  border-color: var(--bs-border-hover-color);
}

/* The title pushes the size buttons and hide to the end */
.home.is-editing .home-w-title {
  margin-right: auto;
}

.home.is-editing .home-w-more,
.home.is-editing .home-w-note {
  display: none;
}

.home.is-editing .card.home-w {
  border: 1.5px solid var(--bs-gray-500);
  box-shadow: none;
  user-select: none;
}

.home.is-editing .home-w-body {
  opacity: 0.4;
  pointer-events: none;
}

.home .card.home-w.is-dragging {
  z-index: 10;
  border-color: var(--bs-primary);
  box-shadow: 0 12px 28px rgba(17, 24, 39, 0.18), 0 2px 6px rgba(17, 24, 39, 0.08);
}

.home-w.is-dragging .home-w-grip {
  color: var(--bs-primary) !important;
  cursor: grabbing;
}

body.home-dragging,
body.home-dragging * {
  cursor: grabbing !important;
}

/* Add widgets: a panel from the right (a sheet on phones) */
.home-add {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1060;
  display: flex;
  flex-direction: column;
  width: 25rem;
  max-width: 100%;
  border-left: 1px solid var(--bs-border-color);
  background: var(--bs-component-bg);
  box-shadow: var(--loon-pop-shadow);
}

.home-add-top {
  display: flex;
  flex: none;
  align-items: center;
  min-height: 3.75rem;
  padding: 0 0.75rem 0 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.home-add-top h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.home-add-top .btn {
  margin-left: auto;
}

.home-add-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 1rem;
}

.home-add-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem 0.375rem;
  color: var(--bs-fg-2);
  font-size: 0.8125rem;
  font-weight: 600;
}

.home-add-head .nav-square {
  width: 1.25rem;
  height: 1.25rem;
  font-size: 0.6875rem;
}

.home-add-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.25rem;
  padding: 0.375rem 1.25rem;
}

.home-add-kind {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: var(--bs-border-radius);
  background: var(--loon-item-hover-bg);
  color: var(--bs-fg-2);
}

.home-add-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.home-add-text b {
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-add-text small {
  color: var(--bs-fg-3);
  font-size: 0.78125rem;
}

.home-add-on {
  display: none;
  flex: none;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  color: var(--bs-fg-3);
  font-size: 0.8125rem;
}

.home-add-btn {
  flex: none;
  margin-left: auto;
}

.home-add-item.is-on .home-add-on {
  display: inline-flex;
}

.home-add-item.is-on .home-add-btn {
  display: none;
}


/* 6. PHONES -------------------------------------------------------------------- */

@media (width < 576px) {
  .home {
    --home-edge: 1rem;
    --home-gap: 0.75rem;
  }

  .home-head {
    align-items: flex-start;
  }

  .home-hello {
    font-size: 1.3125rem;
  }

  /* Create: the primary action as a dark square; Edit home moves to the page's end */
  .home-create-btn {
    width: 2.75rem;
    padding: 0;
    justify-content: center;
    border-color: var(--bs-gray-900);
    background: var(--bs-gray-900);
  }

  .home-create-btn span,
  .home-create-btn .home-caret,
  .home-edit-btn {
    display: none;
  }

  .home-edit-end {
    display: inline-flex;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
  }

  .home.is-editing .home-edit-end {
    display: none;
  }

  /* Small widgets two side by side, the others full width, as tall as they need */
  .home-grid {
    grid-auto-rows: auto;
  }

  .card.home-w {
    min-height: 8.5rem;
    padding: 0.875rem var(--home-edge);
  }

  .home-w[data-size=l] {
    grid-row: auto;
  }

  .home-w[data-size=m] .home-bars,
  .home-w[data-size=l] .home-bars {
    min-height: 6rem;
  }

  .home-big {
    font-size: 1.375rem;
  }

  .home-hbar-label {
    width: 5rem;
  }

  .home-hbar-value {
    min-width: 4.5rem;
  }

  .home-hbar-value span {
    display: none;
  }

  /* Choices open as bottom sheets over the dimmed page */
  .home-menu.show {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    z-index: 1089;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.4) !important;
  }

  .home-add {
    top: auto;
    left: 0;
    width: auto;
    max-height: 85vh;
    border-left: 0;
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.4);
  }

  /* Edit home on a phone: every widget becomes one row of the list – grip, name, size, hide */
  .home.is-editing .card.home-w {
    grid-column: span 2;
    min-height: 0;
    padding: 0.625rem var(--home-edge);
  }

  .home.is-editing .home-w-head {
    margin: 0;
  }

  .home.is-editing .home-w-body {
    display: none;
  }

  .home-editbar .home-actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }

  .home-editbar .home-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}
