/* Self-hosted fonts (Google Fonts is blocked in some regions, so we ship the
   woff2 files ourselves instead of loading from fonts.googleapis.com). */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("assets/fonts/space-grotesk-400.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("assets/fonts/space-grotesk-500.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("assets/fonts/space-grotesk-700.woff2") format("woff2");
}
@font-face {
  font-family: "Orbitron";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("assets/fonts/orbitron-500.woff2") format("woff2");
}
@font-face {
  font-family: "Orbitron";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("assets/fonts/orbitron-700.woff2") format("woff2");
}

:root {
  --bg-a: #0a1020;
  --bg-b: #0f2e3c;
  --card: rgba(13, 20, 36, 0.85);
  --text: #e6f3ff;
  --muted: #9bb5c8;
  --accent: #45ffd0;
  --accent-2: #2ea8ff;
  --danger: #ff5b7a;
  --border: rgba(116, 177, 210, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, rgba(69, 255, 208, 0.14), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(46, 168, 255, 0.18), transparent 38%),
    linear-gradient(145deg, var(--bg-a), var(--bg-b) 65%);
  padding: 24px;
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(36px);
  opacity: 0.4;
  z-index: -1;
  animation: drift 12s ease-in-out infinite alternate;
}

.bg-shape-a {
  width: 240px;
  height: 240px;
  background: #1e7cff;
  top: -70px;
  right: -50px;
}

.bg-shape-b {
  width: 280px;
  height: 280px;
  background: #00d2a8;
  left: -80px;
  bottom: -110px;
}

@keyframes drift {
  from { transform: translateY(0) translateX(0); }
  to { transform: translateY(22px) translateX(14px); }
}

.topbar {
  max-width: 1100px;
  margin: 0 auto 20px;
}

.topbar-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.topbar h1 {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  letter-spacing: 0.08em;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.topbar p {
  color: var(--muted);
  margin: 8px 0 0;
}

.display-currency-control {
  min-width: 170px;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.topbar-controls {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.lang-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.lang-control-label {
  font-size: 0.85rem;
}

.layout {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.section-panel {
  grid-column: span 12;
  position: sticky;
  top: 12px;
  z-index: 20;
  padding: 7px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(16, 30, 50, 0.92), rgba(12, 38, 52, 0.92));
  border: 1px solid rgba(116, 177, 210, 0.22);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.32);
}

.section-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x proximity;
}

.section-tabs::-webkit-scrollbar {
  display: none;
}

.section-tab {
  flex: 1 1 0;
  min-width: 76px;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 9px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s ease, background 0.25s ease, transform 0.15s ease, box-shadow 0.25s ease;
}

.section-tab-icon {
  font-size: 1.18rem;
  line-height: 1;
  filter: grayscale(0.35);
  opacity: 0.85;
  transition: transform 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
}

.section-tab-label {
  font-family: "Space Grotesk", sans-serif;
}

.section-tab:hover {
  color: var(--text);
  background: rgba(46, 168, 255, 0.1);
}

.section-tab:hover .section-tab-icon {
  transform: translateY(-1px) scale(1.05);
  filter: grayscale(0);
  opacity: 1;
}

.section-tab:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.section-tab.active,
.section-tab[aria-selected="true"] {
  color: #04121a;
  background: linear-gradient(135deg, var(--accent), #7af7ff);
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(69, 255, 208, 0.32);
}

.section-tab.active .section-tab-icon,
.section-tab[aria-selected="true"] .section-tab-icon {
  filter: grayscale(0);
  opacity: 1;
  transform: scale(1.08);
}

[data-section] {
  scroll-margin-top: 110px;
}

.tab-section[hidden] {
  display: none !important;
}

.tab-section:not([hidden]) {
  animation: tab-in 0.28s ease;
}

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

.layout > .tab-section {
  grid-column: span 12;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(6px);
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.form-card { grid-column: span 5; }
.controls-card { grid-column: span 7; }
.summary-card { grid-column: span 12; }
.filter-card { grid-column: span 12; }
.daybrowser-card { grid-column: span 12; }
.list-card { grid-column: span 12; }

h2 {
  margin-top: 0;
  font-family: "Orbitron", sans-serif;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

form {
  display: grid;
  gap: 12px;
}

label,
.field {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
}

.amount-row {
  display: flex;
  gap: 8px;
}

.amount-row #amount,
.amount-row #modal-amount {
  flex: 1;
}

.amount-currency {
  width: auto;
  min-width: 92px;
  flex-shrink: 0;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(146, 205, 234, 0.24);
  background: rgba(12, 27, 40, 0.72);
  color: var(--text);
  padding: 10px 12px;
}

button {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  color: #05121a;
  background: linear-gradient(120deg, var(--accent), #7af7ff);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.switch-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.totals-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.totals-grid article {
  border: 1px solid rgba(133, 192, 221, 0.2);
  border-radius: 12px;
  padding: 10px;
  background: rgba(13, 34, 46, 0.5);
}

.totals-grid h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

.totals-grid p {
  margin: 8px 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.converted {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

#expenses-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.expense-item {
  border: 1px solid rgba(133, 192, 221, 0.2);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 6px;
  background: rgba(11, 24, 40, 0.65);
}

.expense-main {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.expense-name {
  min-width: 100%;
  color: #d7f9ff;
}

.expense-tags {
  color: var(--accent);
}

.tag-editor {
  border-radius: 12px;
  border: 1px solid rgba(146, 205, 234, 0.24);
  background: rgba(12, 27, 40, 0.72);
  padding: 8px;
  display: grid;
  gap: 8px;
}

.selected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selected-tags-empty {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 2px 0;
}

.tag-chip {
  border: 1px solid rgba(69, 255, 208, 0.5);
  background: rgba(69, 255, 208, 0.14);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-chip-x {
  font-size: 1rem;
  line-height: 1;
  color: var(--accent);
}

#tag-input {
  border: 1px dashed rgba(146, 205, 234, 0.35);
  background: rgba(8, 20, 32, 0.6);
}

.tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 168px;
  overflow-y: auto;
}

.tag-option {
  border: 1px solid rgba(146, 205, 234, 0.28);
  background: rgba(18, 38, 54, 0.7);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.tag-option:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.tag-option-create {
  border-style: dashed;
  border-color: var(--accent);
  background: rgba(69, 255, 208, 0.12);
}

.tag-option-create strong {
  color: var(--accent);
}

.tag-count {
  background: rgba(146, 205, 234, 0.22);
  border-radius: 999px;
  padding: 0 6px;
  font-size: 0.72rem;
  color: var(--muted);
}

.tag-suggestions-empty {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 4px 2px;
}

.expense-sub {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.delete-btn {
  justify-self: end;
  padding: 6px 10px;
  font-size: 0.85rem;
  color: var(--danger);
  background: transparent;
  border: 1px solid var(--danger);
}

.day-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 4px 0 12px;
  flex-wrap: wrap;
}

.day-nav #day-picker {
  flex: 1;
  min-width: 150px;
}

.nav-arrow {
  width: 44px;
  font-size: 1.4rem;
  line-height: 1;
  padding: 6px 0;
  flex-shrink: 0;
}

.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.day-head h3 {
  margin: 0;
  font-size: 1rem;
  text-transform: capitalize;
}

.day-total {
  color: var(--accent);
  font-weight: 700;
}

.day-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.day-empty {
  color: var(--muted);
  padding: 8px 2px;
}

.console-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.console-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.console-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.console-msg {
  color: var(--text);
  font-size: 0.92rem;
}

.console-item.success {
  border-color: rgba(69, 255, 208, 0.45);
}

.console-item.error {
  border-color: rgba(255, 91, 122, 0.55);
  background: rgba(255, 91, 122, 0.08);
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  margin: 12px 0;
}

.voice-add {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.voice-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid rgba(69, 255, 208, 0.5);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(69, 255, 208, 0.16), rgba(46, 168, 255, 0.16));
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.voice-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(69, 255, 208, 0.18);
}

.voice-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.voice-btn.recording {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(255, 91, 122, 0.14);
  animation: voice-pulse 1.1s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 91, 122, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(255, 91, 122, 0); }
}

.voice-status {
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1;
  min-width: 140px;
}

.voice-status.success { color: var(--accent); }
.voice-status.error { color: var(--danger); }

.photo-btn {
  border-color: rgba(46, 168, 255, 0.5);
  color: var(--accent-2);
  background: linear-gradient(135deg, rgba(46, 168, 255, 0.16), rgba(69, 255, 208, 0.12));
}

.photo-btn:hover {
  box-shadow: 0 8px 22px rgba(46, 168, 255, 0.18);
}

/* Receipt review modal */
.receipt-modal {
  max-width: 640px;
}

.receipt-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 4px;
  flex-wrap: wrap;
}

.receipt-app-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(46, 168, 255, 0.4);
  background: rgba(46, 168, 255, 0.12);
  color: var(--accent-2);
  font-weight: 600;
  font-size: 0.88rem;
}

.receipt-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.receipt-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52vh;
  overflow-y: auto;
  margin: 6px 0 14px;
  padding-right: 4px;
}

.receipt-row {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.receipt-row-top,
.receipt-row-bottom {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.receipt-row-top { align-items: center; }

.receipt-row-name {
  flex: 1 1 180px;
  min-width: 0;
}

.receipt-row-amount {
  flex: 0 0 100px;
  width: 100px;
}

.receipt-row-currency {
  flex: 0 0 80px;
  width: 80px;
}

.receipt-row-date {
  flex: 1 1 140px;
}

.receipt-row-tags {
  flex: 1 1 160px;
}

.receipt-row-note {
  flex: 1 1 160px;
}

.receipt-row-remove {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 9px;
  color: var(--danger);
  border: 1px solid var(--danger);
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.receipt-row-remove:hover {
  background: rgba(255, 91, 122, 0.14);
}

.receipt-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.receipt-view {
  max-width: 92vw;
  width: auto;
}

.receipt-view-img {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  border-radius: 12px;
  margin-top: 10px;
}

.receipt-view-btn {
  justify-self: start;
  padding: 5px 10px;
  font-size: 0.82rem;
  color: var(--accent-2);
  background: rgba(46, 168, 255, 0.1);
  border: 1px solid rgba(46, 168, 255, 0.4);
  border-radius: 9px;
  cursor: pointer;
}

.receipt-view-btn:hover {
  background: rgba(46, 168, 255, 0.2);
}

.sync-row {
  margin: 4px 0 10px;
  min-height: 18px;
}

.sync-status {
  font-size: 0.82rem;
  color: var(--muted);
}

.sync-status.success { color: var(--accent); }
.sync-status.error { color: var(--danger); }

/* ---- Tag catalog ---- */
.tags-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.tags-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.lang-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  padding: 5px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.lang-btn:hover { color: var(--text); }

.lang-btn.active {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #04141a;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(69, 255, 208, 0.25);
}

.tags-toolbar .sync-status {
  margin-left: auto;
}

.tags-toolbar-row2 {
  margin-bottom: 8px;
}

.tags-toolbar button.ghost.small {
  width: 34px;
  padding: 6px 0;
  text-align: center;
  font-size: 0.95rem;
}

#tag-voice-btn.recording {
  border-color: var(--danger);
  color: var(--danger);
  animation: voicePulse 1.1s ease-in-out infinite;
}

@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 91, 122, 0.0); }
  50% { box-shadow: 0 0 0 5px rgba(255, 91, 122, 0.18); }
}

.tag-search-wrap {
  position: relative;
  flex: 1 1 220px;
  display: flex;
  align-items: center;
}

.tag-search-icon {
  position: absolute;
  left: 11px;
  font-size: 0.85rem;
  opacity: 0.7;
  pointer-events: none;
}

.tag-search-input {
  width: 100%;
  padding: 9px 12px 9px 32px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.tag-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.tag-quick-add {
  display: flex;
  gap: 8px;
  flex: 2 1 320px;
}

.tag-quick-add-input {
  flex: 1 1 auto;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.tag-quick-add-input:focus {
  outline: none;
  border-color: var(--accent);
}

.tag-quick-hint {
  margin: -2px 0 12px;
  font-size: 0.78rem;
}

.tag-tree {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tag-node-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tag-children {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-left: 16px;
  padding-left: 12px;
  border-left: 1px dashed rgba(155, 181, 200, 0.28);
}

.tag-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.12s ease;
}

.tag-node:hover {
  border-color: rgba(69, 255, 208, 0.4);
  background: rgba(69, 255, 208, 0.05);
}

.tag-node.editing {
  align-items: flex-start;
}

.tag-node.dragging {
  opacity: 0.45;
}

.tag-node.drop-before {
  box-shadow: 0 -3px 0 0 var(--accent);
}

.tag-node.drop-after {
  box-shadow: 0 3px 0 0 var(--accent);
}

.tag-node.drop-inside {
  border-color: var(--accent);
  background: rgba(69, 255, 208, 0.12);
}

.tag-toggle {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}

.tag-toggle:hover:not(:disabled) {
  color: var(--accent);
  background: rgba(69, 255, 208, 0.1);
}

.tag-toggle.leaf {
  cursor: default;
  opacity: 0.4;
  font-size: 0.6rem;
}

.tag-drag-handle {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: grab;
  opacity: 0.45;
  transition: opacity 0.15s ease, color 0.15s ease;
  user-select: none;
}

.tag-node:hover .tag-drag-handle { opacity: 0.9; }
.tag-drag-handle:active { cursor: grabbing; }

.tag-node-label {
  flex: 1 1 auto;
  font-size: 0.95rem;
  color: var(--text);
}

.tag-node-label.search-hit {
  color: var(--accent);
  font-weight: 600;
}

.tag-count-badge {
  flex: 0 0 auto;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(46, 168, 255, 0.18);
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
}

.tag-node-actions {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 4px;
  opacity: 0.55;
  transition: opacity 0.18s ease;
}

.tag-node:hover .tag-node-actions { opacity: 1; }

.tag-node-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tag-node-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-node-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.tag-node-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

.tag-edit-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--muted);
  flex: 1 1 120px;
}

.tag-edit-field input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.9rem;
}

.tag-edit-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.tag-edit-actions {
  display: inline-flex;
  gap: 6px;
}

button.ghost.primary {
  border-color: var(--accent);
  color: var(--accent);
}

.person-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  background: var(--input-bg, rgba(255, 255, 255, 0.04));
  color: inherit;
  font-size: 0.95rem;
}

.expense-person {
  color: var(--accent);
  font-size: 0.85rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 20, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(160deg, rgba(15, 26, 44, 0.98), rgba(11, 32, 44, 0.98));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  margin-top: 24px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-head h2 {
  margin: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text);
  background: rgba(146, 205, 234, 0.12);
  border: 1px solid var(--border);
}

.modal-date {
  color: var(--muted);
  margin: 6px 0 14px;
  text-transform: capitalize;
}

#modal-form {
  display: grid;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 900px) {
  .topbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-card,
  .controls-card,
  .summary-card,
  .filter-card,
  .daybrowser-card,
  .list-card {
    grid-column: span 12;
  }

  .totals-grid,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .switch-row,
  .expense-sub,
  .list-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-panel {
    top: 6px;
    padding: 6px;
    border-radius: 16px;
  }

  .section-tabs {
    gap: 4px;
  }

  .section-tab {
    min-width: 64px;
    padding: 8px 6px;
    font-size: 0.68rem;
    border-radius: 12px;
  }

  .section-tab-icon {
    font-size: 1.1rem;
  }

  [data-section] {
    scroll-margin-top: 100px;
  }

  .stats-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-breakdown {
    grid-template-columns: 1fr;
  }

  .stats-donut {
    justify-self: center;
  }
}

/* --- Statistics section --- */
.stats-controls {
  margin: 12px 0 6px;
}

.stats-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.stats-presets .chip {
  width: auto;
  min-width: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  line-height: 1.1;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.stats-presets .chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(69, 255, 208, 0.12);
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 18px 0 10px;
}

.stats-card-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
}

.stats-card-label {
  color: var(--muted);
  font-size: 0.8rem;
}

.stats-card-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  font-family: "Orbitron", "Space Grotesk", sans-serif;
}

.stats-card-sub {
  color: var(--accent);
  font-size: 0.85rem;
}

.stats-chart-block {
  margin-top: 20px;
}

.stats-chart-block h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--text);
}

.stats-chart {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 8px 4px;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: "Space Grotesk", sans-serif;
}

.chart-area {
  fill: rgba(69, 255, 208, 0.14);
  stroke: none;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-dot {
  fill: var(--accent);
  stroke: var(--bg-a);
  stroke-width: 1.2;
}

.stats-breakdown {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  padding: 16px;
}

.donut-svg {
  display: block;
  width: 100%;
  max-width: 200px;
  height: auto;
}

.donut-center {
  fill: var(--text);
  font-size: 17px;
  font-weight: 700;
  font-family: "Orbitron", "Space Grotesk", sans-serif;
}

.donut-sub {
  fill: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.donut-seg {
  cursor: pointer;
  transition: opacity 0.18s ease;
}

.donut-seg.dim {
  opacity: 0.3;
}

.stats-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-bar-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-radius: 10px;
  padding: 4px 6px;
  transition: background 0.15s ease;
}

.stats-bar-row.clickable {
  cursor: pointer;
}

.stats-bar-row.hover,
.stats-bar-row.clickable:hover {
  background: rgba(255, 255, 255, 0.05);
}

.stats-bar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.stats-bar-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.stats-bar-label {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-bar-value {
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.82rem;
}

.stats-bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.stats-bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}

.stats-empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 8px;
}

.stats-options-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  margin: 12px 0;
}

.stats-options-row > label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

.stats-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
}

.stats-seg button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 16px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.stats-seg button.active {
  background: var(--accent);
  color: #04222b;
  font-weight: 700;
}

.stats-compare {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.stats-subhint {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.stats-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
}

.stats-delta.up { color: var(--danger); }
.stats-delta.down { color: var(--accent); }
.stats-delta.flat { color: var(--muted); }

.chart-avg {
  stroke: var(--accent-2);
  stroke-width: 1.4;
  stroke-dasharray: 5 4;
  opacity: 0.8;
}

.chart-avg-label {
  fill: var(--accent-2);
  font-size: 10px;
  font-family: "Space Grotesk", sans-serif;
}

.chart-bar {
  fill: var(--accent);
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.chart-svg:hover .chart-bar {
  opacity: 0.6;
}

.chart-guide {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.chart-focus {
  fill: var(--accent);
  stroke: var(--bg-a);
  stroke-width: 2;
  opacity: 0;
  pointer-events: none;
}

.chart-hit {
  cursor: crosshair;
}

.chart-tooltip {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  pointer-events: none;
  background: rgba(7, 18, 30, 0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.chart-tooltip strong {
  color: var(--muted);
  font-weight: 500;
}

.chart-tooltip span {
  color: var(--accent);
  font-weight: 700;
  font-family: "Orbitron", "Space Grotesk", sans-serif;
}

.stats-top-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stats-top-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.stats-top-rank {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(69, 255, 208, 0.14);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.82rem;
}

.stats-top-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.stats-top-name {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-top-meta {
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-top-amount {
  margin-left: auto;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
  font-family: "Orbitron", "Space Grotesk", sans-serif;
}

/* Phone-sized charts: bigger labels and a larger donut so nothing is tiny.
   Placed at the end so these win over the equal-specificity base rules above. */
@media (max-width: 640px) {
  .stats-chart {
    padding: 12px 8px 6px;
  }

  .chart-axis-label {
    font-size: 15px;
  }

  .chart-avg-label {
    font-size: 14px;
  }

  .stats-breakdown {
    /* Must come after the base .stats-breakdown rule, otherwise its 2-column
       grid wins and squeezes the bar list to ~70px on phones. */
    grid-template-columns: minmax(0, 1fr);
    padding: 14px 10px;
    gap: 14px;
  }

  .stats-donut {
    justify-self: center;
  }

  .donut-svg {
    max-width: 240px;
  }

  .donut-center {
    font-size: 24px;
  }

  .donut-sub {
    font-size: 12px;
  }

  .stats-bar-head {
    font-size: 0.95rem;
  }
}

/* ---------------- Home / dashboard ---------------- */
.home-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.home-rate-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(69, 255, 208, 0.06);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.home-rate-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.home-rate-main {
  font-family: "Orbitron", "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.home-rate-extra {
  color: var(--text);
  font-size: 0.9rem;
}

.home-rate-updated {
  color: var(--muted);
  font-size: 0.78rem;
}

.home-quick {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.home-quick h2 {
  margin: 0;
}

.home-quick-name {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.home-quick-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.home-quick-row #home-q-amount {
  flex: 1 1 120px;
  min-width: 0;
}

.home-quick-row #home-q-submit {
  flex: 0 0 auto;
  white-space: nowrap;
}

.home-week,
.home-recent {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.home-week h3,
.home-recent h3 {
  margin: 0;
  font-size: 1rem;
}

.home-week-total {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------------- Generic field / form helpers ---------------- */
.field-title {
  color: var(--muted);
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-actions > button {
  flex: 1 1 140px;
}

.amount-row input[type="number"] {
  flex: 1;
  min-width: 0;
}

/* ---------------- Hierarchical tag picker ---------------- */
.tag-suggestions.tag-picker {
  display: block;
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tag-suggestions.tag-picker[hidden] {
  display: none;
}

.tag-picker > * + * {
  margin-top: 8px;
}

.tag-picker-title {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tag-picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-picker-create {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag-option-cancel {
  color: var(--muted);
}

.tag-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
}

.tag-crumb {
  background: transparent;
  color: var(--accent-2);
  border: none;
  padding: 4px 6px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
}

.tag-crumb.current {
  color: var(--text);
}

.tag-crumb-sep {
  color: var(--muted);
}

.tag-tree-list {
  display: grid;
  gap: 4px;
}

.tag-tree-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border: 1px solid rgba(146, 205, 234, 0.2);
  border-radius: 10px;
  background: rgba(18, 38, 54, 0.55);
}

.tag-tree-row.selected {
  border-color: var(--accent);
  background: rgba(69, 255, 208, 0.12);
}

.tag-tree-pick {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
}

.tag-tree-mark {
  flex: 0 0 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(146, 205, 234, 0.45);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #05121a;
  font-size: 0.78rem;
  font-weight: 700;
}

.tag-tree-row.selected .tag-tree-mark {
  background: var(--accent);
  border-color: var(--accent);
}

.tag-tree-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-tree-drill {
  flex: 0 0 auto;
  min-width: 54px;
  background: rgba(46, 168, 255, 0.12);
  color: var(--accent-2);
  border-left: 1px solid rgba(146, 205, 234, 0.2);
  border-radius: 0 10px 10px 0;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.tag-tree-new {
  display: inline-flex;
}

.tag-editor-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.tag-editor-head .selected-tags {
  flex: 1 1 auto;
  min-width: 0;
}

.tag-panel-toggle {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 0.82rem;
  background: rgba(46, 168, 255, 0.12);
  color: var(--accent-2);
  border: 1px solid rgba(46, 168, 255, 0.4);
  border-radius: 999px;
}

.tag-panel-toggle.active {
  background: rgba(69, 255, 208, 0.16);
  color: var(--accent);
  border-color: var(--accent);
}

.tag-chip span:first-child {
  overflow-wrap: anywhere;
}

/* ---------------- Recent amounts for a product ---------------- */
.amount-recent {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}

.amount-recent[hidden] {
  display: none;
}

.amount-recent-label {
  color: var(--muted);
}

.amount-chip {
  padding: 3px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(69, 255, 208, 0.1);
  color: var(--accent);
  border: 1px solid rgba(69, 255, 208, 0.45);
}

/* ---------------- Templates ---------------- */
.tpl-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 14px;
}

.tpl-block[hidden] {
  display: none;
}

.home-card .tpl-block {
  margin: 0;
}

.tpl-head {
  flex-direction: row !important;
  align-items: center !important;
}

.tpl-head h3 {
  margin: 0;
  font-size: 1rem;
}

.tpl-block button.small,
.tpl-suggest button.small,
.receipt-history button.small {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.tpl-head button.active {
  background: rgba(69, 255, 208, 0.16);
}

.tpl-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tpl-list.managing {
  display: grid;
  gap: 6px;
}

.tpl-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(69, 255, 208, 0.16), rgba(46, 168, 255, 0.12));
  border: 1px solid rgba(69, 255, 208, 0.45);
  color: var(--text);
  text-align: left;
}

.tpl-chip-name {
  font-weight: 700;
  font-size: 0.92rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tpl-chip-meta {
  font-size: 0.76rem;
  color: var(--accent);
  font-weight: 500;
}

.tpl-manage-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tpl-rename {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
}

.tpl-icon-btn {
  flex: 0 0 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: rgba(146, 205, 234, 0.12);
  color: var(--text);
  border: 1px solid var(--border);
}

.tpl-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.tpl-icon-btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.tpl-empty {
  margin: 0;
}

.tpl-suggest {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px dashed rgba(69, 255, 208, 0.4);
  border-radius: 12px;
  padding: 8px 10px;
}

.tpl-suggest[hidden] {
  display: none;
}

.tpl-suggest-actions {
  display: inline-flex;
  gap: 6px;
}

#tpl-modal-form {
  display: grid;
  gap: 12px;
}

.home-quick-tags .tag-editor input {
  border: 1px dashed rgba(146, 205, 234, 0.35);
  background: rgba(8, 20, 32, 0.6);
}

/* ---------------- Expense item actions ---------------- */
.expense-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.expense-actions .delete-btn {
  margin-left: auto;
}

.expense-act {
  padding: 5px 10px;
  font-size: 0.85rem;
  border-radius: 9px;
  background: rgba(146, 205, 234, 0.1);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ---------------- Receipt review: past purchases ---------------- */
.receipt-history {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-size: 0.82rem;
  color: var(--muted);
  border-left: 3px solid var(--accent-2);
  padding: 2px 0 2px 8px;
}

.receipt-history.is-new {
  border-left-color: #ffd24a;
}

.receipt-history > div {
  flex: 1 1 100%;
}

.receipt-history-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.receipt-history-similar {
  color: var(--text);
}

.receipt-new-badge {
  color: #ffd24a;
  font-weight: 600;
}

.receipt-price-delta {
  font-weight: 700;
}

.receipt-price-delta.up {
  color: var(--danger);
}

.receipt-price-delta.down {
  color: #5bffa0;
}

.receipt-price-delta.same {
  color: var(--accent-2);
}

.receipt-auto-tagged {
  color: var(--accent);
}

.receipt-row .receipt-row-tags {
  width: 100%;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(13, 26, 44, 0.96);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 80;
}

.toast[hidden] {
  display: none;
}

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

/* ---------------- Touch targets (>= 44px) for the new controls ---------------- */
.tag-tree-pick,
.tag-tree-drill,
.tag-panel-toggle,
.tag-crumb,
.tpl-chip,
.tpl-icon-btn,
.expense-act,
.expense-actions .delete-btn,
.expense-actions .receipt-view-btn,
.toast-action,
.receipt-use-last,
.tpl-head button,
.tpl-suggest button {
  min-height: 44px;
}

.tag-picker .tag-option,
.tag-chip,
.amount-chip {
  min-height: 40px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.tpl-icon-btn {
  flex-basis: 44px;
  height: 44px;
}

.expense-act {
  min-width: 44px;
}

/* ---------------- Motion (fast, and off for reduced motion) ---------------- */
@keyframes nb-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@keyframes nb-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes nb-toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.modal-overlay:not([hidden]) {
  animation: nb-fade 0.14s ease-out;
}

.modal-overlay:not([hidden]) > .modal {
  animation: nb-pop 0.18s ease-out;
}

.tag-picker:not([hidden]) {
  animation: nb-fade 0.12s ease-out;
}

.toast:not([hidden]) {
  animation: nb-toast-in 0.18s ease-out;
}

.toast.leaving {
  opacity: 0;
  transition: opacity 0.15s ease-in;
}

.tag-tree-row,
.tpl-chip,
.tag-chip {
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.tpl-chip:active,
.tag-tree-pick:active,
.amount-chip:active {
  transform: scale(0.97);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------- Toast with action ---------------- */
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

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

.toast-action {
  flex: 0 0 auto;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 6px 14px;
  border-radius: 10px;
}

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

/* ---------------- Layout polish (390px review) ---------------- */
#receipt-review-hint {
  text-transform: none;
}

.tag-editor-compact:not(.open) > input {
  display: none;
}

.tag-editor-compact .selected-tags {
  min-height: 44px;
  align-items: center;
  cursor: pointer;
}

.receipt-row-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 44px;
  gap: 8px;
}

.receipt-row-top .receipt-row-name {
  grid-column: 1 / -1;
}

.receipt-row-top .receipt-row-amount,
.receipt-row-top .receipt-row-currency {
  width: 100%;
  min-width: 0;
}

.receipt-row-top .receipt-row-remove {
  width: 44px;
  height: 44px;
}

.receipt-row .receipt-row-tags {
  flex: 0 0 auto;
}

.home-quick-row {
  flex-wrap: nowrap;
}

.home-quick-row #home-q-amount {
  flex: 1 1 0;
  min-width: 0;
}

.home-quick-row .amount-currency {
  min-width: 0;
  width: 86px;
}

.home-quick-row #home-q-submit {
  min-height: 44px;
}

@media (max-width: 640px) {
  /* Receipt review: let the whole sheet scroll, keep the actions in reach. */
  .receipt-rows {
    max-height: none;
    overflow: visible;
  }

  .receipt-actions {
    position: sticky;
    bottom: -18px;
    margin: 0 -18px -18px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(11, 32, 44, 0.85), rgba(11, 32, 44, 0.99) 40%);
    border-top: 1px solid var(--border);
    border-radius: 0 0 16px 16px;
  }
}

.modal-date[hidden] + form {
  margin-top: 14px;
}

/* A toast must not cover the action bar of an open sheet. */
body:has(.modal-overlay:not([hidden])) .toast {
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 640px) {
  #modal-form .modal-actions {
    position: sticky;
    bottom: -18px;
    margin: 0 -18px -18px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(11, 32, 44, 0.85), rgba(11, 32, 44, 0.99) 40%);
    border-top: 1px solid var(--border);
    border-radius: 0 0 16px 16px;
    z-index: 2;
  }

  #modal-form .modal-actions > button {
    flex: 1 1 0;
    min-height: 48px;
  }

  .receipt-actions > button {
    flex: 1 1 0;
    min-height: 48px;
  }
}
