:root {
  --bg: #0f1013;
  --text: #f4ecdc;
  --muted: #b9b2a6;
  --card: #191c22;
  --line: #2b313d;
  --accent: #c9b083;
  --warn: #f4a261;
  --positive: #6bcf8b;
  --negative: #f27f7f;
  --shadow: rgba(0, 0, 0, 0.3);
  --app-font: "Courier New", "Courier", monospace;
  --glass-bg: rgba(25, 28, 34, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: 18px;
  /* Compact UI scale */
  --font-base: 0.75rem;
  --font-small: 0.68rem;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 10px;
  --space-lg: 12px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--app-font);
  font-size: var(--font-base);
  font-weight: 300;
  letter-spacing: 0.32px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

h1, h2, h3, h4, h5, h6, th, strong, b {
  font-weight: 300;
}

/* Text selection only in fields the user types into (not labels, AI replies, sheet list, etc.) */
html {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="hidden"]),
textarea,
select {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

input[readonly],
input[disabled],
textarea[readonly],
textarea[disabled],
select[disabled] {
  -webkit-user-select: none;
  user-select: none;
}

/* User’s own chat lines (typed); keep AI bubbles non-selectable */
.chat-bubble.user {
  -webkit-user-select: text;
  user-select: text;
}

#app {
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  padding: var(--space-lg);
  padding-top: calc(var(--space-lg) + env(safe-area-inset-top, 0px));
  padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
  padding-left: calc(var(--space-lg) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--space-lg) + env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
}

.glass-panel {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
}

html.theme-cream, #app.theme-cream {
  --bg: #f5ebe0;
  --text: #2c251c;
  --muted: #6b6156;
  --card: #fffaf5;
  --line: #e5ddd2;
  --accent: #8b6914;
  --shadow: rgba(44, 37, 28, 0.12);
  --warn: #b86b1a;
  --positive: #2d8a4e;
  --negative: #c0392b;
  --glass-bg: rgba(255, 250, 245, 0.72);
  --glass-border: rgba(0, 0, 0, 0.06);
}

html.theme-system, #app.theme-system {
  color-scheme: light dark;
}

html.theme-dark, #app.theme-dark {
  --bg: #0f1013;
  --text: #f4ecdc;
  --muted: #b9b2a6;
  --card: #191c22;
  --line: #2b313d;
  --accent: #c9b083;
  --shadow: rgba(0, 0, 0, 0.3);
  --warn: #f4a261;
  --positive: #6bcf8b;
  --negative: #f27f7f;
  --glass-bg: rgba(25, 28, 34, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
}

/* System light: high-contrast body text (near-black) for legibility */
@media (prefers-color-scheme: light) {
  html.theme-system, #app.theme-system {
    --bg: #f5f3ef;
    --text: #000000;
    --muted: #3f3f3f;
    --card: #fffcf7;
    --line: #e0dcd6;
    --accent: #0f766e;
    --shadow: rgba(0, 0, 0, 0.1);
    --warn: #b45309;
    --positive: #047857;
    --negative: #b91c1c;
    --glass-bg: rgba(255, 252, 247, 0.92);
    --glass-border: rgba(0, 0, 0, 0.1);
  }
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  flex-shrink: 0;
}

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

.brand img {
  width: 40px;
  height: 40px;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.9px;
  font-weight: 700;
  color: var(--accent);
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: var(--font-small);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.view {
  display: none;
}

.view.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Single scroll area per view — only scrolls when content is taller than viewport */
.view-scroll,
.sheet-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Clear fixed “Ask AI” button */
  padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px));
}

.sheet-view-top {
  flex-shrink: 0;
}

/* Sheet stacks above home so swipe-back reveals the list behind (parallax via JS) */
#mainViewStack.view-stack {
  position: relative;
  overflow-x: hidden;
  isolation: isolate;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#mainViewStack.sheet-over #homeView.view-beneath {
  display: block !important;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  width: 100%;
  min-height: 100%;
  z-index: 1;
  pointer-events: none;
}

#mainViewStack.sheet-over #sheetView {
  position: relative;
  z-index: 2;
  background: var(--bg);
  box-shadow: -10px 0 28px var(--shadow);
}

/* Folder mode: root list under current folder (Recently Deleted, etc.) — swipe reveals it */
#mainViewStack.folder-over #homeView {
  position: relative;
  overflow: hidden;
}

#mainViewStack.folder-over #homeFolderUnder {
  display: block !important;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  overflow: hidden;
  background: var(--bg);
  pointer-events: none;
}

#mainViewStack.folder-over #homeScrollLayer.home-folder-front {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  background: var(--bg);
  box-shadow: -10px 0 28px var(--shadow);
}

.home-under-inner {
  padding: 0 2px 12px;
  min-height: 100%;
}

.view-topline-under {
  margin-bottom: var(--space-xs);
  opacity: 0.85;
}

.home-under-hint {
  margin: 0 0 var(--space-sm);
  font-size: var(--font-small);
  color: var(--muted);
}

.sheet-list-under .sheet-item-under {
  opacity: 0.88;
}

.home-under-empty {
  color: var(--muted);
  font-size: var(--font-small);
  margin: var(--space-sm) 0;
}

/* Home layer behind sheet is decorative — no extra scrollbar */
#mainViewStack.sheet-over #homeView.view-beneath .view-scroll,
#mainViewStack.sheet-over #homeView.view-beneath .home-folder-front {
  overflow: hidden;
}

.view-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.view-topline h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 300;
}

.home-topline-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sheet-list {
  display: grid;
  gap: var(--space-sm);
}

/* Swipeable sheet item */
.sheet-item-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}

.swipe-actions-left, .swipe-actions-right {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  z-index: 1;
  padding: 0 6px;
  gap: 5px;
}

.swipe-actions-left {
  right: 0;
  justify-content: flex-end;
}

.swipe-actions-right {
  left: 0;
  justify-content: flex-start;
}

/* Compact action chips — flat, no outer glow; pin has no shadow */
.swipe-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  width: 0;
  height: calc(100% - 16px);
  max-height: 112px;
  cursor: pointer;
  font-family: var(--app-font);
  overflow: hidden;
  padding: 0;
  transition: width 200ms ease, opacity 180ms ease, transform 140ms ease;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: none;
  color: #fff;
  background-clip: padding-box;
}

.swipe-btn-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 54px;
  padding: 8px 6px;
  pointer-events: none;
}

.swipe-btn-label {
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.92;
  text-shadow: none;
}

.swipe-btn .icon-svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  filter: none;
  opacity: 0.95;
}

.swipe-btn-pin {
  background: color-mix(in srgb, var(--accent) 22%, var(--card));
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  box-shadow: none;
}

.swipe-btn-pin .swipe-btn-label {
  color: var(--muted);
  text-shadow: none;
}

.swipe-btn-pin .icon-svg {
  color: var(--accent);
  filter: none;
}

.swipe-btn-share {
  background: linear-gradient(180deg, #3a9d62 0%, #267547 100%);
  border-color: rgba(255, 255, 255, 0.22);
  color: #f4fff8;
}

.swipe-btn-share .swipe-btn-label {
  color: rgba(255, 255, 255, 0.92);
}

.swipe-btn-move {
  background: linear-gradient(180deg, #5c8fd8 0%, #3d6aaf 100%);
  border-color: rgba(255, 255, 255, 0.22);
  color: #f4f8ff;
}

.swipe-btn-move .swipe-btn-label {
  color: rgba(255, 255, 255, 0.92);
}

.swipe-btn-delete {
  background: linear-gradient(180deg, #d64a4a 0%, #b03030 100%);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff5f5;
}

.swipe-btn-delete .swipe-btn-label {
  color: rgba(255, 255, 255, 0.92);
}

html.theme-cream .swipe-btn-pin,
#app.theme-cream .swipe-btn-pin {
  background: color-mix(in srgb, var(--accent) 18%, var(--card));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}


.sheet-item {
  position: relative;
  z-index: 2;
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 4px 14px var(--shadow);
  cursor: pointer;
  transition: border-color 150ms ease;
  will-change: transform;
  touch-action: pan-x pan-y;
}

.sheet-item:hover {
  border-color: var(--accent);
}

.sheet-item.swiping {
  transition: none;
}

.sheet-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.sheet-item h3 {
  margin: 0 0 2px;
  font-size: 0.88rem;
  font-weight: 300;
}

.sheet-pin-badge {
  color: var(--accent);
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  gap: 3px;
}

.sheet-pin-badge .icon-svg {
  width: 12px;
  height: 12px;
}

.sheet-meta {
  display: flex;
  gap: var(--space-md);
  color: var(--muted);
  font-size: var(--font-small);
}

.sheet-empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: var(--space-lg);
  text-align: center;
  font-size: var(--font-small);
}

.sheet-toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-sm);
  align-items: center;
}

#sheetTitleInput {
  font-size: 0.88rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 5px 4px;
}

#sheetTitleInput:focus {
  outline: none;
  border-color: var(--accent);
}

.sheet-toolbar-actions {
  display: flex;
  gap: 8px;
}

.sheet-dates {
  margin-top: var(--space-xs);
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: var(--font-small);
  color: var(--muted);
}

.sheet-meta-line {
  margin-top: var(--space-sm);
}

.sheet-kind-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px var(--space-sm);
  font-size: var(--font-small);
  background: var(--card);
  background: color-mix(in srgb, var(--card) 85%, var(--accent) 15%);
}

.sheet-search {
  margin-top: var(--space-sm);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-sm);
  align-items: center;
}

#homeSearchInput {
  font-size: max(11px, 0.6rem) !important;
  line-height: 1.32;
  padding: 5px 7px !important;
  color: var(--text);
}

.new-sheet-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--shadow);
}

.new-sheet-circle .icon-svg {
  width: 20px;
  height: 20px;
}

.danger-btn {
  color: var(--negative) !important;
  border-color: var(--negative) !important;
}

.sheet-header-card {
  margin-top: var(--space-sm);
  padding: var(--space-md);
  border-radius: 10px;
  border: 1px solid var(--line);
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  background: var(--card);
  font-size: var(--font-small);
}

.sheet-header-card label {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.balance-wrap p {
  margin: 0;
  color: var(--muted);
}

.balance-wrap h3 {
  margin: 2px 0;
  font-size: 1.05rem;
  font-family: var(--app-font);
}

#fundsInput, #rowsTableBody input, #rowsTableBody select, #sheetNotesInput, #sheetMemoList, .ai-panel .chat-bubble {
  font-family: var(--app-font);
}

.balance-wrap.negative h3 {
  color: var(--warn);
}

.header-toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-shell {
  margin-top: var(--space-sm);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  overflow-y: visible;
  background: var(--card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--app-font);
}

th, td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 6px 7px;
  font-size: var(--font-small);
}

tbody tr.row-new {
  animation: rowFadeIn 280ms ease;
}

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

table input, table select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 6px;
  background: transparent;
  color: var(--text);
  font-size: max(14px, 0.75rem);
}

table button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.amount-spend { color: var(--negative); }
.amount-income { color: var(--positive); }

.sheet-footer {
  margin-top: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding-bottom: var(--space-xs);
}

.sheet-footer label[for="sheetNotesInput"] {
  font-size: var(--font-small);
  color: var(--muted);
}

/* Notes — compact only here (global inputs stay default size) */
#sheetNotesInput,
#noteModalInput {
  font-size: max(12px, 0.62rem);
  line-height: 1.4;
  color: var(--text);
}

.filter-banner {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 84%, var(--accent) 16%);
}

.filter-banner button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

textarea, input, select {
  font: inherit;
  font-size: max(15px, 0.8rem);
}

textarea, .sheet-footer input, .sheet-footer select, .sheet-header-card input, .sheet-header-card select, .settings-card input, .settings-card select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px var(--space-sm);
  background: transparent;
  color: var(--text);
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

input:disabled, select:disabled, button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.memo-list {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.voice-bar {
  display: flex;
  gap: 10px;
  align-items: center;
}

.listening-indicator {
  font-size: var(--font-small);
  color: var(--muted);
}

.listening-indicator.active {
  color: var(--positive);
}

.floating-button {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border: none;
  border-radius: 99px;
  padding: var(--space-sm) 14px;
  font-size: var(--font-small);
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ai-panel {
  position: fixed;
  inset: auto 12px 78px 12px;
  max-width: 620px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 18px 32px var(--shadow);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.ai-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-log {
  max-height: 260px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px;
}

.chat-bubble {
  border-radius: 10px;
  padding: 8px 10px;
  max-width: 90%;
  line-height: 1.35;
}

.chat-bubble.user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--accent) 22%, var(--card));
}

.chat-bubble.ai {
  align-self: flex-start;
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
}

.quick-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-suggestions button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
  padding-top: 80px;
  z-index: 20;
}

/* Create Folder must stack above Folders list (both are .modal; later DOM node was covering it) */
#folderModal.modal {
  z-index: 30;
}

.modal-card {
  width: min(620px, 96vw);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 14px 26px var(--shadow);
}

.modal-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.small-btn {
  font-size: 0.72rem;
  padding: 4px 10px !important;
}

.settings-card {
  width: min(720px, 96vw);
}

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

.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.toggle-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.sticky-note textarea {
  background: #fcf4bb;
  color: #352f1f;
}

.attachment-list {
  margin: 10px 0 0;
  padding-left: 18px;
}

.history-list {
  margin: 10px 0 0;
  padding-left: 18px;
  max-height: 45vh;
  overflow: auto;
}

.history-list li {
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.history-revert-btn {
  flex-shrink: 0;
  padding: 3px 8px !important;
  font-size: 0.75rem;
  border-radius: 6px !important;
  opacity: 0.7;
  transition: opacity 150ms ease;
}

.history-revert-btn:hover {
  opacity: 1;
}

.history-time {
  color: var(--muted);
  margin-right: 8px;
}

.attachment-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact {
  width: min(340px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-popup {
  width: min(300px, 88vw);
  padding: 6px 0;
  border-radius: 14px;
  overflow: hidden;
}

.menu-popup-title {
  margin: 0;
  padding: 10px 16px 6px;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 100ms ease;
}

.menu-item:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.menu-item:active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.menu-item .icon-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.menu-item-danger {
  color: var(--negative);
}

.menu-item-danger .icon-svg {
  opacity: 1;
}

.menu-item-muted {
  color: var(--muted);
  justify-content: center;
}

.menu-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 12px;
}

button {
  font: inherit;
}

.icon-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon-button .icon-svg {
  width: 20px;
  height: 20px;
}

.icon-button, .secondary, .primary {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: var(--font-small);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: transparent;
  font-weight: 300;
}

.icon-button {
  padding: 5px 7px;
}

.hidden {
  display: none !important;
}

.status-toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(18px);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 30;
  max-width: min(92vw, 760px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 14px var(--shadow);
}

.status-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.drag-handle {
  cursor: grab;
  user-select: none;
  touch-action: none;
  color: var(--muted);
  font-size: 1.1rem;
}

.drag-handle:active {
  cursor: grabbing;
}

tr.dragging {
  opacity: 0.4;
}

tr.drag-over td {
  border-top: 2px solid var(--accent);
}

.row-num {
  color: var(--muted);
  text-align: right;
  min-width: 28px;
}

.add-row-btn {
  margin-top: 8px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-style: dashed;
}

table .icon-svg {
  width: 18px;
  height: 18px;
}

.row-note .icon-svg, .row-file .icon-svg, .row-delete .icon-svg {
  width: 18px;
  height: 18px;
}

/* Select bar */
.select-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--card) 85%, var(--accent) 15%);
}

.select-bar-actions {
  display: flex;
  gap: 6px;
}

.sheet-item.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--card) 88%, var(--accent) 12%);
}

.sheet-item .select-check {
  width: 20px;
  height: 20px;
  border: 2px solid var(--muted);
  border-radius: 4px;
  flex-shrink: 0;
}

.sheet-item.selected .select-check {
  border-color: var(--accent);
  background: var(--accent);
}

/* View transition for swipe-back */
.view {
  transition: transform 0.25s ease;
}

.view.sliding {
  transition: none;
}

/* Folder bar */
.folder-bar {
  margin-bottom: 8px;
}

.folder-bar button {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

.folder-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 40vh;
  overflow: auto;
}

.folder-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 100ms ease;
}

.folder-list-item:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.folder-list-item .icon-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}

/* Attachments view */
.attachments-view-content {
  max-height: 50vh;
  overflow: auto;
}

.attachments-view-content h4 {
  margin: 12px 0 4px;
  color: var(--accent);
  font-size: 0.85rem;
}

.attachments-view-content ul {
  margin: 0;
  padding-left: 18px;
}

.attachments-view-content li {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 860px) {
  .sheet-header-card {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  body {
    font-size: 0.7rem;
  }

  #app {
    padding: var(--space-sm);
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
  }

  .table-shell {
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: visible;
  }

  th, td {
    padding: 4px 3px;
  }

  table input, table select {
    padding: 4px 3px;
    border-radius: 5px;
    font-size: inherit;
  }

  table button {
    padding: 4px;
    border-radius: 5px;
  }

  table .icon-svg, .row-note .icon-svg, .row-file .icon-svg, .row-delete .icon-svg {
    width: 14px;
    height: 14px;
  }

  .drag-handle .icon-svg {
    width: 12px;
    height: 12px;
  }

  .row-num {
    min-width: 16px;
    font-size: inherit;
  }

  .add-row-btn {
    padding: 6px;
    font-size: inherit;
  }

  .brand img {
    width: 32px;
    height: 32px;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .icon-button {
    padding: 5px 6px;
  }

  .icon-button .icon-svg {
    width: 18px;
    height: 18px;
  }

  .sheet-meta {
    font-size: 0.78rem;
    flex-wrap: wrap;
    gap: 6px;
  }

  .balance-wrap h3 {
    font-size: 1rem;
  }

  .floating-button {
    padding: 8px 12px;
    font-size: 11px;
  }

  .new-sheet-circle {
    width: 34px;
    height: 34px;
  }

  .new-sheet-circle .icon-svg {
    width: 18px;
    height: 18px;
  }
}
