/* fin.css - finance tab: tiles, operations, breakdown, assets */

  /* a segmented thumb sitting inside a card: the default one is card-colored
     and would vanish there in dark mode */
  :root { --seg-thumb: var(--card); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --seg-thumb: #636366; }
  }
  :root[data-theme="dark"] { --seg-thumb: #636366; }

  .view-fin,
  .fin-grid,
  .fin-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* ---------- Tiles ---------- */

  .fin-tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .fin-tile {
    background: var(--card);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 18px 20px 17px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }
  .fin-tile:last-child { grid-column: 1 / -1; }

  .fin-tile-main {
    appearance: none;
    border: none;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    grid-column: 1 / -1;
    padding: 22px 24px 20px;
    transition: transform 0.2s var(--spring);
    touch-action: manipulation;
  }
  .fin-tile-main:active { transform: scale(0.985); }

  .fin-tile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .fin-tile-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-secondary);
  }

  .fin-tile-value {
    font-size: clamp(21px, 2.5vw, 26px);
    font-weight: 700;
    letter-spacing: -0.022em;
    line-height: 1.22;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fin-tile-main .fin-tile-value {
    font-size: clamp(32px, 5vw, 40px);
    letter-spacing: -0.028em;
    line-height: 1.14;
    margin-top: 2px;
  }
  .fin-tile-value.neg { color: var(--danger); }

  .fin-tile-sub {
    font-size: 13px;
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--text-secondary);
    min-height: 17px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fin-rate { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
  .fin-rate:empty { display: none; }

  /* which currency the tab speaks: a tiny segmented control, read-only -
     the whole tile is the button */
  .fin-curs {
    display: inline-flex;
    gap: 1px;
    background: var(--chip-bg);
    border-radius: 980px;
    padding: 2px;
  }
  .fin-curs i {
    font-style: normal;
    font-size: 12px;
    font-weight: 600;
    width: 24px;
    height: 20px;
    border-radius: 980px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: background 0.2s, color 0.2s;
  }
  .fin-curs i.on {
    background: var(--seg-thumb);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  }

  @media (min-width: 920px) {
    .view-fin, .fin-col { gap: 20px; }
    .fin-tiles { grid-template-columns: 1.5fr 1fr 1fr 1fr; gap: 20px; }
    .fin-tile-main, .fin-tile:last-child { grid-column: auto; }
    .fin-tile:not(.fin-tile-main) { padding-top: 22px; }
    .fin-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 20px;
      align-items: start;
    }
  }

  /* ---------- Wallets ---------- */

  .fin-wallets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }

  .fin-wallet {
    appearance: none;
    border: none;
    font: inherit;
    color: inherit;
    text-align: left;
    background: var(--card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 12px 16px 12px;
    min-width: 0;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    cursor: pointer;
    transition: transform 0.2s var(--spring), box-shadow 0.2s;
    touch-action: manipulation;
  }
  .fin-wallet:active { transform: scale(0.975); }
  .fin-wallet[aria-pressed="true"] { box-shadow: var(--shadow), inset 0 0 0 2px var(--accent); }

  .fin-wallet-name {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-secondary);
  }
  .fin-wallet-name .dot { background: var(--gc, var(--text-tertiary)); }
  .fin-wallet-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fin-wallet-sum {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fin-wallet-sum.neg { color: var(--danger); }
  .fin-wallet-parts {
    font-size: 12px;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .fin-wallet-add {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: transparent;
    box-shadow: inset 0 0 0 1.5px var(--separator);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-tertiary);
    transition: color 0.15s, box-shadow 0.15s, transform 0.2s var(--spring);
  }
  .fin-wallet-add:hover { color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
  .fin-wallet-input { width: 100%; min-width: 0; padding: 5px 10px; }

  /* ---------- Month strip ---------- */

  .month-strip .ws-cell { max-width: none; padding: 7px 0 6px; gap: 5px; }

  .ms-bar {
    width: 14px;
    height: 24px;
    display: flex;
    align-items: flex-end;
    border-radius: 4px;
    background: var(--chip-bg);
    overflow: hidden;
  }
  .ms-fill {
    width: 100%;
    border-radius: 4px;
    background: var(--text-tertiary);
    transition: height 0.45s var(--ease-out);
  }
  .ms-cell.today .ms-fill { background: var(--accent); }
  .ms-cell.sel .ms-bar { background: color-mix(in srgb, var(--card) 22%, transparent); }
  .ms-cell.sel .ms-fill { background: var(--card); }

  /* ---------- Record type, add row ---------- */

  .fin-modes-wrap { padding: 0 28px 4px; }
  .fin-modes .tab-thumb { width: calc((100% - 4px) / 4); background: var(--seg-thumb); }
  .fin-modes .tab-btn { flex: 1; width: auto; min-width: 0; font-size: 12.5px; }

  .fin-pill {
    appearance: none;
    border: none;
    flex-shrink: 0;
    position: relative;
    min-width: 32px;
    height: 28px;
    padding: 0 10px;
    border-radius: 980px;
    background: var(--chip-bg);
    color: var(--text-secondary);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s var(--spring);
    touch-action: manipulation;
  }
  .fin-pill:hover { background: var(--btn-hover); color: var(--text); }
  .fin-pill:active { transform: scale(0.94); }
  .fin-pill + .fin-pill { margin-left: -6px; }

  /* the native date field lies invisible over the pill, so a tap opens the
     system picker and the pill only has to show the chosen day */
  .fin-date-pill.off-today { background: var(--accent-soft); color: var(--accent); }
  .fin-date-pill input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: none;
    opacity: 0;
    cursor: pointer;
  }
  .fin-date-pill input::-webkit-calendar-picker-indicator {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    cursor: pointer;
  }
  .fin-date-pill:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

  .add-row.nudge { animation: fin-nudge 0.32s var(--ease-out); }
  @keyframes fin-nudge {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    45% { transform: translateX(5px); }
    70% { transform: translateX(-3px); }
  }

  /* chip rows under the input: wallet, category, subcategory, transfer ends */
  .fin-pick { padding: 2px 0 4px; }
  .fin-chip-row { padding-bottom: 8px; }
  .chips-cap {
    flex-shrink: 0;
    min-width: 58px;
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-tertiary);
  }
  .fin-sub-row .chips-cap { justify-content: flex-end; padding-right: 6px; }
  .fin-sub-row .chip { font-size: 12px; padding: 6px 11px; }
  .fin-sub-row .dot { width: 7px; height: 7px; }
  .chip-pair { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; }
  .chip-glyph { display: inline-flex; color: var(--gc, currentColor); }
  .chip[aria-pressed="true"] .chip-glyph { color: color-mix(in srgb, var(--gc, currentColor) 70%, var(--card)); }

  .view-fin .carry { animation: none; }

  /* ---------- Operation rows ---------- */

  .fin-day { padding-top: 16px; padding-bottom: 2px; }
  .fin-day .section-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
  }

  .fin-ico {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gc, var(--text-tertiary));
  }
  .fin-ico.k-inc { --gc: var(--g-green); }
  .fin-ico.k-inv { --gc: var(--g-indigo); }
  .fin-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gc, var(--text-tertiary));
  }

  .fin-row-sub {
    margin-left: 9px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
  }
  .fin-row-sub:empty { display: none; }
  .fin-row.k-bal .task-label, .fin-row.k-val .task-label { color: var(--text-secondary); }

  .fin-amt {
    flex-shrink: 0;
    font-size: 17px;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--text);
  }
  .fin-amt.hidden { display: none; }
  .fin-amt.plus { color: color-mix(in srgb, var(--success) 82%, var(--text)); }
  .fin-row.k-bal .fin-amt, .fin-row.k-val .fin-amt { color: var(--text-secondary); }

  .fin-edit .edit-input { padding: 11px 0 5px; }
  .fin-ico.k-xfer { --gc: var(--g-teal); }

  /* ---------- Breakdown ---------- */

  .fin-note {
    font-size: 13.5px;
    line-height: 1.5;
    letter-spacing: -0.01em;
    color: var(--text-tertiary);
    padding: 0 28px 8px;
  }
  .fin-note.hidden { display: none; }

  .fin-cats { list-style: none; padding: 0 16px 8px; }

  .fin-cat {
    appearance: none;
    border: none;
    background: transparent;
    font: inherit;
    color: inherit;
    text-align: left;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 10px 12px 11px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s var(--spring);
    touch-action: manipulation;
  }
  .fin-cat:hover { background: var(--btn-hover); }
  .fin-cat:active { transform: scale(0.99); }
  .fin-cat[aria-pressed="true"] { background: var(--accent-soft); }

  .fin-cat-top {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
  }
  .fin-cat-top .dot { align-self: center; background: var(--gc, var(--text-tertiary)); }
  .fin-cat-name {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .fin-cat-delta {
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .fin-cat-delta.up { color: var(--danger); }
  .fin-cat-delta.down { color: color-mix(in srgb, var(--success) 82%, var(--text)); }
  .fin-cat-sum {
    margin-left: auto;
    padding-left: 8px;
    font-size: 15px;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .fin-cat-pct {
    min-width: 34px;
    text-align: right;
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
  }

  .fin-bar {
    display: block;
    height: 6px;
    border-radius: 980px;
    background: var(--chip-bg);
    overflow: hidden;
  }
  .fin-bar-fill {
    display: block;
    height: 100%;
    border-radius: 980px;
    background: var(--gc, var(--text-tertiary));
    transition: width 0.45s var(--ease-out);
  }

  /* ---------- Assets ---------- */

  .fin-inv-meta { display: flex; align-items: center; gap: 9px; }
  .fin-inv-meta.hidden { display: none; }
  .fin-inv-meta .section-count { margin-left: 0; padding-left: 0; }

  .fin-asset .habit-body { gap: 2px; padding: 11px 0 11px; }
  .fin-asset .task-label { padding: 0; }
  .fin-asset .edit-input { padding: 11px 0; }
  .fin-asset-sub {
    font-size: 13px;
    letter-spacing: -0.01em;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
  }
  .fin-asset-put { white-space: nowrap; }

  /* worth on top, what it made underneath - the usual portfolio row */
  .fin-asset-right {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
  }

  .fin-pl {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    padding: 3px 8px;
    border-radius: 980px;
    white-space: nowrap;
  }
  .fin-pl.hidden { display: none; }
  .fin-pl.up {
    color: color-mix(in srgb, var(--success) 78%, var(--text));
    background: color-mix(in srgb, var(--success) 15%, transparent);
  }
  .fin-pl.down {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 12%, transparent);
  }

  .fin-worth {
    appearance: none;
    border: none;
    background: transparent;
    flex-shrink: 0;
    font: inherit;
    font-size: 17px;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--text);
    padding: 4px 9px;
    margin-right: -9px;
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
  }
  .fin-asset-right .fin-pl { font-size: 11.5px; padding: 2px 7px; }
  .fin-worth:hover { background: var(--btn-hover); color: var(--accent); }
  .fin-worth-input { width: 150px; text-align: right; font-size: 15px; flex-shrink: 0; }

  @media (max-width: 480px) {
    .fin-tile { border-radius: 18px; padding: 15px 16px 14px; }
    .fin-tile-main { padding: 18px 18px 16px; }
    .fin-modes-wrap { padding: 0 20px 4px; }
    .fin-modes .tab-btn { font-size: 12px; }
    .fin-note { padding: 0 20px 8px; }
    .fin-cats { padding: 0 8px 8px; }
    .view-fin .add-row { gap: 10px; }
    .fin-worth-input { width: 124px; }
    .fin-row-sub { display: block; margin-left: 0; white-space: normal; }
    .fin-asset-when { display: none; }
  }

  /* ---------- Breakdown: what a category is made of ---------- */

  .fin-cat-hint {
    font-size: 12px;
    letter-spacing: -0.01em;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fin-cat.open { background: var(--accent-soft); }

  .fin-subcats { list-style: none; padding: 2px 0 6px 27px; }
  .fin-subcat {
    appearance: none;
    border: none;
    background: transparent;
    font: inherit;
    color: inherit;
    text-align: left;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 7px 12px 8px;
    border-radius: 10px;
    transition: background 0.15s;
    touch-action: manipulation;
  }
  button.fin-subcat { cursor: pointer; }
  button.fin-subcat:hover { background: var(--btn-hover); }
  .fin-subcat[aria-pressed="true"] { background: var(--accent-soft); }
  .fin-subcat-name {
    font-size: 14px;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  div.fin-subcat .fin-subcat-name { color: var(--text-secondary); }
  .fin-subcat .fin-cat-sum { font-size: 14px; }
  .fin-subcat .fin-cat-pct { font-size: 12px; }
  .fin-subcat .fin-bar { height: 4px; }
  .fin-subcat .fin-bar-fill { opacity: 0.75; }

  /* ---------- Inline edit: the same chip rows, a size down ---------- */

  .fin-edit-pick { padding: 0 0 6px; }
  .fin-edit-pick .fin-chip-row { padding: 0 0 6px; gap: 6px; }
  .fin-edit-pick .chips-cap { min-width: 52px; font-size: 11.5px; }
  .fin-edit-pick .chip { font-size: 12px; padding: 5px 10px; gap: 6px; }
  .fin-edit-pick .dot { width: 7px; height: 7px; }

  @media (max-width: 480px) {
    .fin-wallets { grid-template-columns: 1fr 1fr; gap: 10px; }
    .fin-wallet { border-radius: 15px; padding: 11px 14px; }
    .chips-cap { min-width: 0; padding-right: 2px; }
    /* on a phone every chip row is one line that scrolls sideways, so the
       form stays three rows tall however many categories there are */
    .fin-chip-row {
      flex-wrap: nowrap;
      overflow-x: auto;
      overscroll-behavior-x: contain;
      scrollbar-width: none;
      -webkit-overflow-scrolling: touch;
    }
    .fin-chip-row::-webkit-scrollbar { display: none; }
    .fin-chip-row .chip, .fin-chip-row .chip-pair, .fin-chip-row .chip-input { flex-shrink: 0; }
    .fin-chip-row .chip-name { max-width: none; }
    .fin-subcats { padding-left: 20px; }
  }

  @media (max-width: 480px) {
    /* an exchange: what left on top, what arrived underneath */
    .fin-row.k-xfer .fin-amt { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
    .fin-amt-to { font-size: 13px; color: var(--text-secondary); }
  }

  /* ---------- Asset currency ---------- */

  /* the icon slot of an asset row is its currency: ₽ or $, a click flips it */
  .fin-asset-cur {
    appearance: none;
    border: none;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    margin-top: 13px;
    border-radius: 50%;
    padding: 0;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--g-indigo);
    background: color-mix(in srgb, var(--g-indigo) 14%, transparent);
    cursor: pointer;
    position: relative;
    transition: background 0.15s, transform 0.15s var(--spring);
    touch-action: manipulation;
  }
  .fin-asset-cur::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
  .fin-asset-cur:hover { background: color-mix(in srgb, var(--g-indigo) 24%, transparent); }
  .fin-asset-cur:active { transform: scale(0.88); }
  .fin-asset { align-items: flex-start; }
  .fin-asset .fin-asset-right { padding-top: 8px; }
  .fin-asset .del { margin-top: 9px; }

  .fin-asset-under { display: inline-flex; align-items: center; gap: 7px; min-height: 18px; }
  .fin-asset-conv {
    font-size: 12px;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .fin-asset-conv:empty { display: none; }

  @media (max-width: 480px) {
    .fin-row.k-inv .fin-amt { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
  }

  /* the asset row on a phone: the left caption may shorten, the right column
     stacks its hint over the badge - neither runs into the other */
  .fin-asset .habit-body { overflow: hidden; }
  .fin-asset-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  @media (max-width: 480px) {
    .fin-asset-under { flex-direction: column; align-items: flex-end; gap: 3px; }
  }
