/* ============================================================
   STACK — Personal Budget
   Aesthetic: Editorial utility. Warm blacks, amber data, tight grid.
   ============================================================ */

/* Fonts loaded via <link> in index.html for faster rendering */

:root {
  --bg: #141414;
  --card: #1a1a1a;
  --surface: #1e1e1e;
  --surface-up: #252525;
  --border: #2e2e2e;
  --border-light: #383838;

  --text: #d4d0c8;
  --text-secondary: #8a8780;
  --text-dim: #8a887f;

  --amber: #c8a44e;
  --amber-dim: #a68a3a;
  --amber-glow: rgba(200, 164, 78, 0.08);
  --green: #5a9a6a;
  --green-text: #7bc48e;
  --red: #b05050;
  --red-text: #d47272;
  --yellow: #b89940;
  --blue: #4f86d9;
  --blue-text: #8db5f2;

  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --display: 'Bebas Neue', 'Impact', 'Arial Black', sans-serif;
  --header-height: 68px;
  --radius: 4px;
  --radius-md: 6px;

  /* 4pt spacing scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html { scroll-behavior: smooth; }

body {
  color-scheme: dark;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  margin: 0;
  padding: var(--space-lg) var(--space-lg) calc(env(safe-area-inset-bottom) + var(--header-height) + var(--space-xl)) var(--space-lg);
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--space-lg));
  background: var(--bg);
  color: var(--text);
  -webkit-overflow-scrolling: touch;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.modal-open {
  overflow: hidden;
}

/* Semantic colors */
.asset { color: var(--green-text); }
.liability { color: var(--red-text); }
.positive-amount { color: var(--green-text); }

/* ---- Layout ---- */

.container {
  margin: 0 auto;
  padding: 0;
  max-width: 760px;
}

/* ---- Landing Page ---- */

#landing {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg) url('images/backdrop.jpg') center/cover no-repeat;
  padding: var(--space-xl);
  transition: opacity 0.3s ease;
}

#landing.hidden {
  display: none;
}

.landing-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xl);
  height: 100%;
}

.landing-main {
  flex: 1;
  display: flex;
  align-items: center;
}

.landing-title {
  font-family: var(--display);
  font-size: clamp(120px, 28vw, 220px);
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text);
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s ease;
}

.landing-title:hover,
.landing-title:focus-visible {
  color: var(--amber);
}

.landing-tagline {
  font-family: var(--mono);
  font-size: clamp(14px, 3vw, 17px);
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
  letter-spacing: 0.02em;
}

.landing-arrow {
  background: transparent;
  border: 2px solid var(--border-light);
  color: var(--text);
  width: 64px;
  height: 64px;
  cursor: pointer;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  line-height: 1;
  padding: 0;
}

.landing-arrow:hover {
  border-color: var(--amber);
  color: var(--amber);
}

.landing-arrow:active {
  background: var(--amber-glow);
  border-color: var(--amber);
  color: var(--amber);
}

.landing-arrow:focus-visible {
  outline: 2px solid var(--amber-dim);
  outline-offset: 3px;
}

#landing-settings-btn {
  position: fixed;
  bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
  right: var(--space-lg);
}

/* ---- Grid ---- */

.lists {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-xl);
}

@media (max-width: 599px) {
  body { font-size: 16px; }
}

@media (min-width: 1024px) {
  body { padding: var(--space-xl) var(--space-xl) calc(env(safe-area-inset-bottom) + var(--header-height) + var(--space-xl)) var(--space-xl); }
}

/* ---- Section Cards ---- */

.list {
  background: var(--card);
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: none;
}

.list h2 {
  margin: 0 0 var(--space-md) 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}

.section-total {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: -0.02em;
}

.list h2 .addItemSectionBtn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 20px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
}

.list h2 .addItemSectionBtn:hover {
  color: var(--amber);
  border-color: var(--amber-dim);
}

.list h2 .addItemSectionBtn:active {
  background: var(--amber-glow);
  color: var(--amber);
  border-color: var(--amber-dim);
}

/* ---- Item Cards ---- */

.item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: var(--space-sm);
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
}

.item:not(.item-readonly):hover {
  border-color: var(--border);
}

.item .item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  cursor: pointer;
}

.item-readonly .item-content {
  cursor: default;
}

.item .item-info {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.item .item-name {
  font-weight: 500;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.item .item-amount {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: -0.03em;
}

.item .item-meta-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.item .meta {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.3;
  font-family: var(--mono);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Inline Actions ---- */

.item .item-actions-inline {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.icon-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  padding: 0;
}

.icon-action-btn:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
}

.icon-action-btn:active {
  background: var(--amber-glow);
  border-color: var(--amber);
  color: var(--amber);
}

.icon-action-btn.edit {
  color: var(--text-dim);
}

.icon-action-btn.edit:hover {
  color: var(--amber);
  border-color: var(--amber-dim);
}

.icon-action-btn.edit:active {
  background: var(--amber-glow);
  color: var(--amber);
}

/* ---- Progress Bar ---- */

.item-progress {
  width: 100%;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
  margin-top: var(--space-xs);
}

.item-progress-bar {
  transition: width 0.4s cubic-bezier(0.25, 1, 0.5, 1);
  height: 100%;
  border-radius: 1px;
  /* width set via JS after DOM insertion so transition fires */
}

.item-progress-bar.good { background: var(--green); }
.item-progress-bar.warning { background: var(--yellow); }
.item-progress-bar.danger { background: var(--red); }

.item-progress-bar.warning,
.item-progress-bar.danger {
  animation: progressUrgent 2s ease-in-out infinite;
}

@keyframes progressUrgent {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.82; }
}

/* ---- Modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 9999;
  padding: 0;
  animation: fadeIn 0.15s ease;
  transition: opacity 0.15s ease;
}

.modal-overlay.closing {
  opacity: 0;
  pointer-events: none;
}

.modal-overlay.closing .modal {
  transform: translateY(100%);
  opacity: 0;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal {
  background: var(--card);
  padding: var(--space-xl);
  padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom));
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: inherit;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  animation: sheetUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.15s ease;
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: var(--space-xl);
  }
  .modal {
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding-top: var(--space-xl);
    padding-bottom: var(--space-xl);
    max-height: calc(100vh - 40px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .modal-overlay.closing .modal {
    transform: translateY(12px);
    opacity: 0;
  }
  @keyframes slideUp {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}

.modal h2,
.modal h3 {
  margin: 0 0 var(--space-lg) 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.modal label {
  display: block;
  margin-bottom: var(--space-md);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.modal label.toggle-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  text-transform: none;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: normal;
}

.modal label.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--amber);
}

.modal input[type="text"],
.modal input[type="number"],
.modal input[type="date"],
.modal select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  font-size: 15px;
  font-family: var(--font);
  margin-top: var(--space-xs);
  transition: border-color 0.15s;
}

.modal input[type="number"],
.modal input[type="date"] {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: -0.02em;
}

.modal input:focus,
.modal select:focus {
  outline: none;
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 1px var(--amber-glow);
}

.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-xl);
}

.modal .actions button {
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  background: var(--surface);
  color: var(--text);
}

.modal .actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.modal .actions button:active {
  opacity: 0.8;
}

@media (max-width: 599px) {
  .modal .actions {
    flex-direction: column;
    gap: var(--space-sm);
  }
  .modal .actions button {
    width: 100%;
    justify-content: center;
    padding: 12px 20px;
    min-height: 48px;
  }
  .modal .actions button#_item_ok,
  .modal .actions button#_spend_ok,
  #gist-save-btn {
    flex: none;
    order: -1;
  }
}

.modal .actions button#_item_ok,
.modal .actions button#_spend_ok,
#gist-save-btn {
  background: var(--amber-dim);
  border-color: var(--amber-dim);
  color: var(--bg);
  flex: 1;
}

.modal .actions button#_item_spend {
  background: #4a5a6a;
  border-color: #4a5a6a;
  color: var(--bg);
}

.modal .actions button#_item_spend:hover {
  background: #3a4a5a;
  border-color: #3a4a5a;
}

.modal .actions button#_item_ok:hover,
.modal .actions button#_spend_ok:hover,
#gist-save-btn:hover {
  background: #8a7a3a;
  border-color: #8a7a3a;
}

.modal .actions button#_item_cancel,
.modal .actions button#_spend_cancel {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.modal .actions button.delBtn {
  background: transparent;
  border-color: var(--red);
  color: var(--red-text);
}

.modal .actions button.delBtn:hover {
  background: rgba(176, 80, 80, 0.1);
}

/* ---- Gist Controls ---- */

.gist-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.gist-controls input {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  font-size: 14px;
  font-family: var(--mono);
}

.gist-controls input:focus {
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 1px var(--amber-glow);
}

.status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: var(--space-xs) var(--space-sm);
}

/* ---- Backup Section ---- */

.backup-section {
  margin-top: var(--space-xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.backup-section h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.backup-buttons {
  display: flex;
  gap: var(--space-sm);
}

.backup-btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  font-family: var(--font);
  min-height: 44px;
  transition: border-color 0.15s, color 0.15s, opacity 0.15s;
}

.backup-btn:hover {
  border-color: var(--border-light);
  color: var(--text);
}

.backup-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.backup-btn:active {
  opacity: 0.8;
}

.backup-section small {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}

/* ---- Install App Section ---- */

.install-app-section {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.install-app-section small {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}


/* ---- Footer Bar ---- */

.footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg) calc(var(--space-sm) + env(safe-area-inset-bottom)) var(--space-lg);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background: var(--card);
  border-top: 1px solid var(--border);
  -webkit-user-select: none;
  user-select: none;
  box-shadow: none;
}

.footer-left {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.available-amount {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.available-amount #available {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 24px;
  color: var(--amber);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.available-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

body.onboarding .footer-bar {
  display: none;
}

#landing:not(.hidden) ~ .container .footer-bar {
  display: none;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 16px;
  border-radius: var(--radius);
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
}

.icon-btn {
  position: relative;
}

.icon-btn:active {
  background: var(--amber-glow);
  border-color: var(--amber-dim);
  color: var(--amber);
}

.icon-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  font-family: var(--mono);
}

.icon-btn:hover::after,
.icon-btn:focus-visible::after {
  opacity: 1;
}

/* ---- Inline Error ---- */
.inline-error {
  color: var(--red-text);
  font-size: 12px;
  font-family: var(--mono);
  margin-top: var(--space-xs);
  display: block;
}

/* ---- Undo Toast ---- */
#undo-toast {
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

#undo-toast .undo-timer {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--amber);
  opacity: 0.3;
  transform-origin: left center;
  animation: undoCountdown 6s linear forwards;
}

@keyframes undoCountdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

#_undo_btn:hover {
  filter: brightness(1.12);
}

#_undo_btn:active {
  transform: scale(0.96);
}

/* ---- Checkbox ---- */

.modal input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-right: 8px;
  accent-color: var(--amber);
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

/* checkbox scale removed — decorative motion, quieter tool */

/* ---- Spend History ---- */

.modal h4 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--space-lg) 0 var(--space-sm) 0;
  color: var(--text-dim);
}

.modal ul {
  margin: 0;
  padding: 0;
  font-size: 13px;
  color: var(--text-secondary);
  list-style: none;
}

.modal ul.spend-history-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: var(--space-xs);
  font-family: var(--mono);
  font-size: 12px;
}

.modal ul.spend-history-list li:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.modal ul.spend-history-list .spend-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal ul.spend-history-list .delete-spend-btn {
  background: transparent;
  border: none;
  color: var(--red-text);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.15s;
  flex-shrink: 0;
}

.modal ul.spend-history-list .delete-spend-btn:hover {
  background: rgba(176, 80, 80, 0.12);
}

.modal ul.spend-history-list .delete-spend-btn:active {
  background: rgba(176, 80, 80, 0.2);
}

.modal ul.spend-history-list .delete-spend-btn:focus-visible {
  outline: 2px solid var(--red-text);
  outline-offset: 2px;
}

.modal small {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 12px;
}

/* ---- Empty State ---- */

.list-items:empty::after {
  display: block;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  padding: 24px 16px;
  opacity: 0.6;
}

.list-items[data-section="accounts"]:empty::after {
  content: "Add an account to start tracking your net worth.";
}

.list-items[data-section="expenses"]:empty::after {
  content: "No expenses yet. Tap + to add an item.";
}

.list-items[data-section="history"]:empty::after {
  content: "No recent activity.";
}

/* ---- App Title (visually hidden h1) ---- */
.app-title {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Touch Feedback ---- */

@media (hover: none) {
  .item:not(.item-readonly):active {
    background: var(--surface-up);
  }
  .icon-btn:active,
  .icon-action-btn:active {
    background: var(--amber-glow);
  }
}

/* ---- Scrollbar ---- */

.list-items {
  -webkit-overflow-scrolling: touch;
}

::-webkit-scrollbar {
  width: 0;
  height: 0;
}

* {
  scrollbar-width: none;
}

/* ---- Install Instructions ---- */

.install-instructions {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}

.install-method {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-md);
  border: 1px solid var(--border);
}

.install-method h4 {
  margin: 0 0 var(--space-sm) 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.install-method ol {
  margin: 0;
  padding-left: 18px;
}

.install-method li {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  line-height: 1.4;
}

.install-method li:last-child {
  margin-bottom: 0;
}

.install-method li strong {
  color: var(--text);
}

.install-note {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  margin: var(--space-md) 0 0 0;
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ---- Autofill Modal ---- */

.autofill-freq-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.autofill-freq-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.autofill-freq-row select {
  flex: 1;
}

.autofill-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: var(--space-sm);
}

.autofill-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.autofill-item {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: var(--space-sm);
  cursor: pointer;
  transition: background 0.1s;
  -webkit-user-select: none;
  user-select: none;
}

.autofill-item:last-child {
  border-bottom: none;
}

.autofill-item:hover {
  background: var(--surface-up);
}

/* Dim content when unchecked (but keep unaffordable amount at full red) */
.autofill-item:has(.autofill-cb:not(:checked)) .autofill-rec-name,
.autofill-item:has(.autofill-cb:not(:checked)) .autofill-rec-meta,
.autofill-item:has(.autofill-cb:not(:checked)) .autofill-item-amount:not(.autofill-item-amount--unaffordable) {
  opacity: 0.35;
}

.autofill-item .autofill-cb {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--amber);
  cursor: pointer;
}

.autofill-rec-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.autofill-rec-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.autofill-item-amount {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--green-text);
  white-space: nowrap;
  flex-shrink: 0;
}

.autofill-item-amount--unaffordable {
  color: var(--red-text);
}

.autofill-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 0 0;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.autofill-total-amount {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: -0.02em;
}

.autofill-remaining {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.autofill-remaining span:last-child {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.autofill-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: var(--space-xl) 0 var(--space-sm);
  margin: 0;
}

.modal .actions button#_af_fill {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--bg);
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.modal .actions button#_af_fill:hover:not(:disabled) {
  background: var(--amber-dim);
  border-color: var(--amber-dim);
}

.modal .actions button#_af_fill:disabled {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
  opacity: 0.5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.modal .actions button#_af_fill:disabled::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btnSpinner 0.6s linear infinite;
  flex-shrink: 0;
}

.modal .actions button#_af_cancel {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

/* ---- Help Tooltips ---- */

.gist-field {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.gist-field input {
  flex: 1;
}

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: help;
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
  background: transparent;
}

.help-tip:hover,
.help-tip:focus-visible {
  border-color: var(--amber-dim);
  color: var(--amber);
}

.help-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: normal;
  width: 220px;
  max-width: 90vw;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  line-height: 1.4;
}

.help-tip:hover::after,
.help-tip:focus-visible::after {
  opacity: 1;
}

/* ---- Gist Setup Steps ---- */

/* ---- Help Section ---- */

.help-section {
  margin-top: var(--space-lg);
  border-top: 1px solid var(--border);
  padding-top: var(--space-md);
}

.help-section summary {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  cursor: pointer;
  padding: var(--space-xs) 0;
  transition: color 0.15s;
  border-radius: var(--radius);
}

.help-section summary:hover {
  color: var(--text-secondary);
}

.help-section summary:focus-visible {
  outline: 2px solid var(--amber-dim);
  outline-offset: 2px;
}

.help-content {
  margin-top: var(--space-sm);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.help-content p {
  margin: 0 0 var(--space-sm) 0;
}

.help-content p:last-child {
  margin-bottom: 0;
}

.help-content strong {
  color: var(--text);
}

/* ---- Gist Loading State ---- */

#gist-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#gist-save-btn:disabled::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btnSpinner 0.6s linear infinite;
  flex-shrink: 0;
}

.gist-controls.gist-loading #status {
  animation: loadingPulse 1.2s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@keyframes btnSpinner {
  to { transform: rotate(360deg); }
}

/* ---- Animation: Button hover/active feedback ---- */

.icon-action-btn {
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.icon-action-btn:hover {
  background: var(--surface-up);
}

.list h2 .addItemSectionBtn {
  transition: color 0.15s, border-color 0.15s;
}

.modal .actions button {
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.modal .actions button:not(#_confirm_no):not(#_confirm_yes):hover {
  background: var(--surface-up);
  border-color: var(--border-light);
}

#_confirm_yes:hover {
  background: var(--amber-dim);
  border-color: var(--amber-dim);
}

#_confirm_no:hover {
  background: var(--surface-up);
  border-color: var(--border-light);
}

/* ---- Animation: Item card hover ---- */

.item {
  transition: background 0.1s, border-color 0.15s, transform 0.08s cubic-bezier(0.25, 1, 0.5, 1);
}

.item:not(.item-readonly):hover {
  border-color: var(--border-light);
}

.item:not(.item-readonly):active {
  transform: scale(0.98);
}

.item-clickable:focus-visible {
  outline: 2px solid var(--amber-dim);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.icon-btn:focus-visible,
.icon-action-btn:focus-visible,
.addItemSectionBtn:focus-visible,
.modal .actions button:focus-visible,
.backup-btn:focus-visible {
  outline: 2px solid var(--amber-dim);
  outline-offset: 2px;
}

/* ---- Animation: Section total color transitions ---- */

.section-total {
  transition: color 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Animation: Input focus ring ---- */

.modal input:focus,
.modal select:focus {
  transition: border-color 0.15s, box-shadow 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Animation: Empty state fade ---- */

.list-items:empty::after {
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Animation: Item stagger ---- */

@keyframes itemStagger {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Accessibility: Reduced motion ---- */

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