/*
 * Shared chrome for every Centgenie route. Loaded as an asset (`/assets/styles/centgenie.css`)
 * from each view's head rather than duplicated into four `style.css` files — the per-view
 * stylesheets carry only what is unique to that screen.
 *
 * Centgenie commits to a dark surface regardless of the site theme, so the tokens are declared
 * on the shell instead of inherited from `:root`.
 */

.cg {
  --cg-bg: #0a0a0a;
  --cg-raise: #161616;
  --cg-fg: #fcfcfc;
  --cg-muted: #8a8a8a;
  --cg-line: #242424;
  --cg-up: #ff453a;
  --cg-down: #32d74b;

  /*
   * One curve and one duration for the whole app, so a hover on a keypad key and a hover on a
   * ledger row feel like the same surface. `--cg-duration` is what the motion preference moves:
   * setting it to 0s stops every transition without any of them needing to know.
   */
  --cg-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --cg-duration: 140ms;
  --cg-duration-slow: 220ms;

  color-scheme: dark;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 30rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(var(--topbar-height, 4rem) + 0.5rem) 1.25rem 6.5rem;
  box-sizing: border-box;
  background: var(--cg-bg);
  color: var(--cg-fg);
  font-variant-numeric: tabular-nums;
}

.cg [hidden] {
  display: none !important;
}

/*
 * The preference, applied on the view element so every screen picks it up the same way. It can
 * only take motion away — the platform's `prefers-reduced-motion` is honoured underneath
 * regardless, so a system that asked for less never gets more because an app setting said so.
 */
[motion='off'] .cg,
[motion='off'] .cg * {
  --cg-duration: 0s;
  --cg-duration-slow: 0s;
  transition-duration: 0s !important;
  animation-duration: 0s !important;
}

@media (prefers-reduced-motion: reduce) {
  .cg,
  .cg * {
    --cg-duration: 0s;
    --cg-duration-slow: 0s;
    transition-duration: 0s !important;
    animation-duration: 0s !important;
  }
}

/*
 * The picker is app-agnostic and themed through its own properties; this is Centgenie telling
 * it what its surface looks like, including how fast it is allowed to move.
 */
.cg datetime-picker {
  --dtp-surface: var(--cg-raise);
  --dtp-fg: var(--cg-fg);
  --dtp-muted: var(--cg-muted);
  --dtp-line: var(--cg-line);
  --dtp-duration: var(--cg-duration);
  --dtp-ease: var(--cg-ease);
}

/* Top bar ------------------------------------------------------------------ */

.cg-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2.5rem;
}

.cg-topbar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.cg-round {
  display: inline-flex;
  flex: none;
  text-decoration: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--cg-raise);
  color: var(--cg-fg);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background-color var(--cg-duration) var(--cg-ease),
    color var(--cg-duration) var(--cg-ease),
    transform var(--cg-duration) var(--cg-ease);
}

.cg-round:hover {
  background: color-mix(in srgb, var(--cg-fg), transparent 82%);
}

.cg-round[primary]:hover {
  background: color-mix(in srgb, var(--cg-fg), #fff 20%);
}

/* A small dip on press, so a tap reads as landing rather than as nothing happening. */
.cg-round:active {
  transform: scale(0.92);
}

.cg-round[primary] {
  background: var(--cg-fg);
  color: var(--cg-bg);
}

.cg-round:focus-visible,
.cg-segment:focus-visible,
.cg-key:focus-visible {
  outline: 2px solid var(--cg-fg);
  outline-offset: 2px;
}

/* Hero --------------------------------------------------------------------- */

.cg-hero {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.5rem 0 0.25rem;
}

.cg-hero .cg-caption {
  margin: 0;
  color: var(--cg-muted);
  font-size: 0.95rem;
}

.cg-amount {
  margin: 0;
  font-size: clamp(2.6rem, 13vw, 3.6rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.02em;
}

.cg-amount .cg-cents {
  font-size: 0.55em;
  vertical-align: super;
}

.cg-trend {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--cg-muted);
}

.cg-trend .cg-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

.cg-trend[direction='up'] .cg-chip {
  color: var(--cg-up);
  background: color-mix(in srgb, var(--cg-up), transparent 85%);
}

.cg-trend[direction='down'] .cg-chip {
  color: var(--cg-down);
  background: color-mix(in srgb, var(--cg-down), transparent 85%);
}

.cg-trend[direction='flat'] .cg-chip {
  background: var(--cg-raise);
}

/* Segmented controls ------------------------------------------------------- */

.cg-segmented {
  display: inline-flex;
  align-self: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 999px;
  background: var(--cg-raise);
}

.cg-segment {
  padding: 0.45rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cg-muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition:
    background-color var(--cg-duration) var(--cg-ease),
    color var(--cg-duration) var(--cg-ease);
}

/* Hovering an inactive segment previews it; hovering the active one has nothing to say. */
.cg-segment:hover:not([active='true']) {
  background: color-mix(in srgb, var(--cg-fg), transparent 92%);
  color: var(--cg-fg);
}

.cg-segment[active='true'] {
  background: color-mix(in srgb, var(--cg-fg), transparent 82%);
  color: var(--cg-fg);
}

/* Rows --------------------------------------------------------------------- */

.cg-group-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1rem 0 0.5rem;
  color: var(--cg-muted);
  font-size: 0.95rem;
}

.cg-rows {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cg-row {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--cg-line);
  text-align: left;
  background: none;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  color: inherit;
  font: inherit;
  width: 100%;
  cursor: default;
  text-decoration: none;
  box-sizing: border-box;
}

/* Only the rows that go somewhere behave like it. */
a.cg-row,
button.cg-row {
  cursor: pointer;
}

a.cg-row,
button.cg-row {
  transition: background-color var(--cg-duration) var(--cg-ease);
}

a.cg-row:hover,
a.cg-row:focus-visible {
  background: color-mix(in srgb, var(--cg-fg), transparent 94%);
}

a.cg-row:focus-visible {
  outline: 2px solid var(--cg-fg);
  outline-offset: -2px;
}

/* Inside a swipe wrapper the row must fill it, so the tray is only ever revealed by sliding. */
.swipe .cg-row {
  width: 100%;
}

.cg-row .cg-chevron {
  color: var(--cg-muted);
  font-size: 1.2rem;
  transition: opacity 140ms ease;
}

/*
 * The chevron and the options handle want the same corner. Hovering is the moment the row stops
 * being only a destination, so the chevron steps aside for the handle rather than crowding it.
 */
.swipe:hover .cg-row .cg-chevron {
  opacity: 0;
}

/* Available to screen readers, absent from the page. */
.cg-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.cg-row .cg-emoji {
  font-size: 1.6rem;
  line-height: 1;
}

.cg-row .cg-title {
  display: block;
  font-size: 1.05rem;
}

.cg-row .cg-sub,
.cg-row .cg-alt {
  display: block;
  color: var(--cg-muted);
  font-size: 0.9rem;
}

.cg-row .cg-values {
  text-align: right;
}

.cg-row .cg-value {
  display: block;
  font-size: 1.05rem;
}

/* Empty + status ----------------------------------------------------------- */

.cg-empty {
  padding: 2.5rem 1rem;
  color: var(--cg-muted);
  text-align: center;
  font-size: 0.95rem;
}

.cg-note {
  margin: 0;
  color: var(--cg-muted);
  font-size: 0.8rem;
}

/*
 * Status and meta lines are empty until they have something to say. In a flex column an empty
 * paragraph is still a row and still earns a gap, so it reads as unexplained padding —
 * `display: none` takes it out of the layout rather than just making it invisible.
 */
.cg-note:empty,
.cg-hint:empty {
  display: none;
}

/* Bottom tabs -------------------------------------------------------------- */

.cg-tabs {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  display: flex;
  gap: 0.25rem;
  padding: 0.3rem;
  border: 1px solid var(--cg-line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--cg-raise), transparent 10%);
  backdrop-filter: blur(12px);
  z-index: 5;
}

.cg-tabs a {
  padding: 0.5rem 1rem;
  border-radius: 999px;
  color: var(--cg-muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition:
    background-color var(--cg-duration) var(--cg-ease),
    color var(--cg-duration) var(--cg-ease);
}

.cg-tabs a:hover:not([active='true']) {
  background: color-mix(in srgb, var(--cg-fg), transparent 90%);
  color: var(--cg-fg);
}

.cg-tabs a[active='true'] {
  background: var(--cg-fg);
  color: var(--cg-bg);
}

/* Modals ------------------------------------------------------------------- */

/*
 * A modal `<dialog>` centres itself with the UA's `margin: auto`, which the site's reset zeroes
 * out — leaving every dialog pinned to the top-left corner. Restating it here is what puts them
 * back in the middle.
 */
.cg-modal {
  position: fixed;
  inset: 0;
  width: min(26rem, calc(100vw - 2rem));
  max-height: min(42rem, calc(100dvh - 2rem));
  margin: auto;
  padding: 1.25rem;
  overflow-y: auto;
  border: 1px solid var(--cg-line);
  border-radius: 1.25rem;
  background: var(--cg-raise);
  color: var(--cg-fg);
  color-scheme: dark;
}

.cg-modal::backdrop {
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(2px);
}

/* Forms -------------------------------------------------------------------- */

.cg-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cg-field > .cg-segmented {
  align-self: flex-start;
}

.cg-field > span {
  color: var(--cg-muted);
  font-size: 0.85rem;
}

.cg-control {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--cg-line);
  border-radius: 0.75rem;
  background: var(--cg-raise);
  color: var(--cg-fg);
  font: inherit;
  box-sizing: border-box;
  transition:
    border-color var(--cg-duration) var(--cg-ease),
    background-color var(--cg-duration) var(--cg-ease),
    box-shadow var(--cg-duration) var(--cg-ease);
}

/*
 * The outline lives on the border rather than on `outline`, so the box does not grow when it
 * lights up — a field that shifts its neighbours on focus is a field that feels loose.
 */
.cg-control:hover {
  border-color: color-mix(in srgb, var(--cg-fg), transparent 70%);
}

.cg-control:focus-visible,
.cg-control:focus {
  border-color: var(--cg-fg);
  box-shadow: 0 0 0 1px var(--cg-fg);
  outline: none;
}

.cg-control::placeholder {
  color: color-mix(in srgb, var(--cg-muted), transparent 30%);
}

.cg-button {
  padding: 0.7rem 1.2rem;
  border: 0;
  border-radius: 999px;
  background: var(--cg-fg);
  color: var(--cg-bg);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color var(--cg-duration) var(--cg-ease),
    color var(--cg-duration) var(--cg-ease),
    transform var(--cg-duration) var(--cg-ease),
    opacity var(--cg-duration) var(--cg-ease);
}

.cg-button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--cg-fg), #fff 25%);
}

.cg-button[ghost]:hover:not(:disabled) {
  background: color-mix(in srgb, var(--cg-fg), transparent 82%);
}

.cg-button[danger]:hover:not(:disabled) {
  background: color-mix(in srgb, var(--cg-up), transparent 68%);
}

.cg-button:active:not(:disabled) {
  transform: scale(0.97);
}

.cg-button[ghost] {
  background: var(--cg-raise);
  color: var(--cg-fg);
}

.cg-button[danger] {
  background: color-mix(in srgb, var(--cg-up), transparent 80%);
  color: var(--cg-up);
}

.cg-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
