:root {
  color-scheme: light;

  --paper-0: #fbfcfc;
  --paper-50: #f3f7f6;
  --paper-100: #e9f0ee;
  --paper-200: #d9e4e1;
  --paper-300: #c4d3cf;
  --ink-950: #13211f;
  --ink-800: #233936;
  --ink-700: #344b47;
  --ink-600: #4b625e;
  --ink-500: #667a76;
  --ink-400: #536864;
  --teal-50: #edf8f5;
  --teal-100: #d6eee8;
  --teal-300: #75bbae;
  --teal-500: #138474;
  --teal-600: #0a6a5f;
  --teal-700: #07584f;
  --red-50: #fff1f0;
  --red-600: #b83b35;

  --surface-canvas: var(--paper-50);
  --surface-raised: var(--paper-0);
  --surface-overlay: #ffffff;
  --surface-sunken: var(--paper-100);
  --surface-rail: #e5efec;
  --surface-accent-soft: var(--teal-50);
  --text-primary: var(--ink-950);
  --text-secondary: var(--ink-600);
  --text-tertiary: var(--ink-400);
  --border-subtle: rgb(19 33 31 / 7%);
  --border-default: rgb(19 33 31 / 14%);
  --border-strong: rgb(19 33 31 / 24%);
  --accent: var(--teal-600);
  --accent-hover: var(--teal-700);
  --accent-soft: rgb(15 118 105 / 9%);
  --accent-ring: rgb(19 132 116 / 28%);
  --text-on-accent: #f8fffd;
  --success: var(--teal-600);
  --danger: var(--red-600);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 32px;

  --radius-input: 6px;
  --radius-card: 10px;
  --radius-dialog: 14px;
  --radius-round: 999px;

  --shadow-small: 0 1px 2px rgb(35 57 54 / 5%), 0 3px 8px rgb(35 57 54 / 4%);
  --shadow-raised: 0 4px 10px rgb(35 57 54 / 7%), 0 1px 3px rgb(35 57 54 / 7%);
  --shadow-overlay: 0 20px 45px rgb(19 33 31 / 16%), 0 5px 12px rgb(19 33 31 / 8%);

  --motion-instant: 80ms;
  --motion-fast: 120ms;
  --motion-base: 200ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --z-sticky: 20;
  --z-modal: 40;
  --z-toast: 50;

  --font-ui: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --surface-canvas: #10201d;
  --surface-raised: #172a26;
  --surface-overlay: #1d302c;
  --surface-sunken: #0c1a18;
  --surface-rail: #142723;
  --surface-accent-soft: #17342e;
  --text-primary: #edf5f2;
  --text-secondary: #b5c7c2;
  --text-tertiary: #7f9992;
  --border-subtle: rgb(237 245 242 / 7%);
  --border-default: rgb(237 245 242 / 14%);
  --border-strong: rgb(237 245 242 / 24%);
  --accent: #58bbaa;
  --accent-hover: #74cbbc;
  --accent-soft: rgb(88 187 170 / 12%);
  --accent-ring: rgb(88 187 170 / 30%);
  --text-on-accent: #10201d;
  --success: #74cbbc;
  --danger: #ef8a83;
  --shadow-small: inset 0 1px 0 rgb(255 255 255 / 4%), 0 1px 2px rgb(0 0 0 / 16%);
  --shadow-raised: inset 0 1px 0 rgb(255 255 255 / 6%), 0 5px 14px rgb(0 0 0 / 18%);
  --shadow-overlay: inset 0 1px 0 rgb(255 255 255 / 7%), 0 24px 48px rgb(0 0 0 / 36%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--surface-canvas);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.4;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

button {
  border: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

svg {
  display: block;
}

button svg,
a svg,
.search-box svg,
.select-wrap svg,
.table-state svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: var(--z-toast);
  top: var(--space-2);
  left: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-input);
  background: var(--accent);
  color: var(--text-on-accent);
  transform: translateY(-160%);
  transition: transform var(--motion-fast) var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 3px solid var(--accent-ring);
  outline-offset: 2px;
  transition: outline-color var(--motion-fast) var(--ease-out);
}

.app-shell {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border-subtle);
  background: var(--surface-rail);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand small {
  margin-top: 1px;
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--surface-raised);
  box-shadow: var(--shadow-small);
  color: var(--accent);
}

.brand-mark svg {
  width: 28px;
  height: 28px;
}

.brand-mark svg path:first-child {
  fill: currentColor;
  stroke: none;
}

.brand-mark svg path:last-child {
  fill: none;
  stroke: var(--surface-raised);
  stroke-linecap: round;
  stroke-width: 1.6;
}

.brand-mark-small {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
}

.brand-mark-small svg {
  width: 24px;
  height: 24px;
}

.rail-nav {
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-8);
}

.rail-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: var(--space-3);
  padding: 0 var(--space-3);
  border-radius: var(--radius-input);
  color: var(--text-secondary);
  font-weight: 500;
  transition: background-color var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}

.rail-link svg {
  width: 18px;
  height: 18px;
}

.rail-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.rail-stamp {
  position: relative;
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-8);
  padding: var(--space-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-input);
  background: var(--surface-raised);
  box-shadow: var(--shadow-small);
}

.rail-stamp::before,
.rail-stamp::after {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-round);
  background: var(--surface-rail);
  content: "";
  transform: translateY(-50%);
}

.rail-stamp::before {
  left: -6px;
}

.rail-stamp::after {
  right: -6px;
}

.rail-stamp span,
.rail-stamp small {
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.rail-stamp strong {
  font-family: var(--font-mono);
  font-size: 28px;
  font-variant-numeric: tabular-nums slashed-zero;
  letter-spacing: -0.04em;
}

.rail-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-6);
}

.sync-state {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.sync-dot,
.julia-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: var(--radius-round);
}

.sync-dot,
.julia-dot.is-yes {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.julia-dot.is-no {
  border: 1px solid var(--text-tertiary);
  background: transparent;
}

.rail-actions {
  display: flex;
  gap: var(--space-1);
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}

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

.theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-icon-moon {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: block;
}

.workspace {
  min-width: 0;
  padding: 0 var(--space-6) var(--space-8);
}

.topbar {
  position: sticky;
  z-index: var(--z-sticky);
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--surface-canvas) 92%, transparent);
  backdrop-filter: blur(12px);
}

.topbar h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.kicker,
.section-label {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kicker {
  margin-bottom: 3px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.mobile-brand,
.mobile-theme {
  display: none;
}

.primary-button,
.ghost-button,
.text-button,
.filter-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border-radius: var(--radius-input);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out), box-shadow var(--motion-fast) var(--ease-out), transform var(--motion-instant) var(--ease-out);
}

.primary-button svg,
.ghost-button svg {
  width: 18px;
  height: 18px;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  box-shadow: 0 1px 2px rgb(11 95 85 / 16%), 0 4px 10px rgb(11 95 85 / 10%);
  color: var(--text-on-accent);
}

.ghost-button {
  border: 1px solid var(--border-default);
  background: var(--surface-raised);
  color: var(--text-secondary);
  box-shadow: var(--shadow-small);
}

.text-button {
  min-height: 44px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.danger-text {
  color: var(--danger);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(304px, 376px) minmax(0, 1fr);
  gap: var(--space-6);
  max-width: 1540px;
  margin: 0 auto;
  padding-top: var(--space-6);
}

section {
  scroll-margin-top: 88px;
}

.capture-column {
  align-self: start;
  position: sticky;
  top: 96px;
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  background: var(--surface-raised);
  box-shadow: var(--shadow-raised);
}

.capture-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.capture-heading h2,
.ledger-heading h2,
.dialog-header h2 {
  margin-top: 2px;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.date-ticket {
  display: grid;
  min-width: 76px;
  gap: 1px;
  padding: var(--space-2) var(--space-3);
  border-left: 1px dashed var(--border-strong);
  background: var(--surface-accent-soft);
  text-align: right;
}

.date-ticket span {
  color: var(--text-secondary);
  font-size: 11px;
}

.date-ticket strong {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums slashed-zero;
}

.entry-form {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
}

.field-group {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.field-group label {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.field-group label small {
  color: var(--text-tertiary);
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-input);
  outline: none;
  background: var(--surface-overlay);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color var(--motion-fast) var(--ease-out), box-shadow var(--motion-fast) var(--ease-out), background-color var(--motion-fast) var(--ease-out);
}

input,
select {
  padding: 0 var(--space-3);
}

textarea {
  min-height: 84px;
  padding: var(--space-3);
  resize: vertical;
  line-height: 1.45;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgb(184 59 53 / 13%);
}

.paired-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-3);
}

.input-prefix {
  position: relative;
}

.input-prefix > span {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: var(--space-3);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  transform: translateY(-50%);
}

.input-prefix input {
  padding-left: 28px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

#amount-x,
#edit-amount-x {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  appearance: none;
  padding-right: 40px;
  cursor: pointer;
}

.select-wrap svg {
  position: absolute;
  top: 50%;
  right: var(--space-3);
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  pointer-events: none;
  transform: translateY(-50%);
}

.field-error {
  min-height: 0;
  color: var(--danger);
  font-size: var(--text-xs);
}

.field-error:not(:empty) {
  min-height: 17px;
}

.field-meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.form-status {
  min-height: 0;
  color: var(--danger);
  font-size: var(--text-xs);
}

.form-status:not(:empty) {
  min-height: 17px;
}

.save-button {
  width: 100%;
  min-height: 48px;
}

.save-button[aria-busy="true"],
.primary-button[aria-busy="true"] {
  cursor: wait;
  opacity: 0.72;
}

.ledger-column {
  min-width: 0;
}

.metric-strip {
  display: grid;
  grid-template-columns: minmax(250px, 1.5fr) minmax(150px, 0.75fr) minmax(150px, 0.75fr);
  gap: var(--space-3);
}

.metric-card {
  display: grid;
  min-height: 112px;
  align-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  background: var(--surface-raised);
  box-shadow: var(--shadow-small);
}

.metric-primary {
  grid-template-columns: minmax(0, 1fr) 120px;
  align-items: end;
  background: var(--surface-accent-soft);
}

.metric-card p,
.metric-card span {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
}

.metric-card strong {
  display: block;
  margin: var(--space-1) 0 2px;
  font-family: var(--font-mono);
  font-size: 28px;
  font-variant-numeric: tabular-nums slashed-zero;
  letter-spacing: -0.04em;
  line-height: 1;
}

.metric-primary strong {
  color: var(--accent);
  font-size: 36px;
}

.sparkline {
  width: 120px;
  height: 34px;
  overflow: visible;
}

.sparkline polyline {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.sparkline-fill {
  fill: var(--accent-soft);
  stroke: none;
}

.ledger-panel {
  margin-top: var(--space-4);
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  background: var(--surface-raised);
  box-shadow: var(--shadow-small);
}

.ledger-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-4) var(--space-3);
}

.result-count {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.search-box {
  position: relative;
  display: flex;
  min-width: 200px;
  max-width: 320px;
  flex: 1 1 240px;
  align-items: center;
}

.search-box > svg {
  position: absolute;
  z-index: 1;
  left: var(--space-3);
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  pointer-events: none;
}

.search-box input {
  height: 44px;
  padding-right: 48px;
  padding-left: 40px;
  font-size: var(--text-sm);
}

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.search-box kbd {
  position: absolute;
  right: var(--space-2);
  padding: 2px 5px;
  border: 1px solid var(--border-default);
  border-radius: 4px;
  background: var(--surface-sunken);
  color: var(--text-tertiary);
  pointer-events: none;
}

.filter-group {
  display: flex;
  padding: 3px;
  border: 1px solid var(--border-default);
  border-radius: 8px;
  background: var(--surface-sunken);
}

.filter-button {
  min-width: 48px;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: 5px;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.filter-button.is-active {
  background: var(--surface-raised);
  box-shadow: var(--shadow-small);
  color: var(--accent);
}

.keyboard-hint {
  margin-left: auto;
  color: var(--text-tertiary);
  font-size: 11px;
  white-space: nowrap;
}

.keyboard-hint kbd {
  color: var(--text-secondary);
}

.table-wrap {
  position: relative;
  min-height: 360px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-spacing: 0 4px;
  border-collapse: separate;
  padding: 0 var(--space-2) var(--space-2);
}

th,
td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
}

th {
  height: 36px;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}

td {
  height: 44px;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-raised);
  vertical-align: middle;
}

tbody tr {
  position: relative;
  border-radius: var(--radius-input);
  outline-offset: -2px;
  transition: transform var(--motion-instant) var(--ease-out), box-shadow var(--motion-fast) var(--ease-out);
}

tbody td:first-child {
  border-left: 1px solid var(--border-subtle);
  border-radius: var(--radius-input) 0 0 var(--radius-input);
}

tbody td:last-child {
  border-right: 1px solid var(--border-subtle);
  border-radius: 0 var(--radius-input) var(--radius-input) 0;
}

.align-right,
.cell-number {
  text-align: right;
}

.cell-date,
.cell-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums slashed-zero;
  white-space: nowrap;
}

.cell-date {
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.cell-name {
  min-width: 150px;
  font-weight: 500;
}

.name-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
}

.initial-mark {
  display: grid;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  place-items: center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-round);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
}

.name-text,
.notes-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes-text {
  display: block;
  max-width: 220px;
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.notes-empty {
  color: var(--text-tertiary);
}

.julia-state {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.row-action {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-input);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--text-xs);
  opacity: 1;
  transition: background-color var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out), opacity var(--motion-fast) var(--ease-out);
}

.row-action svg {
  width: 16px;
  height: 16px;
}

tbody tr:focus-within .row-action,
tbody tr:focus .row-action {
  opacity: 1;
}

tbody tr.is-new td {
  box-shadow: inset 0 0 0 2px var(--accent-ring);
}

.skeleton-row td {
  border-color: transparent;
}

.skeleton-row span {
  display: block;
  width: 100%;
  height: 24px;
  border-radius: 4px;
  background: var(--surface-sunken);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.table-state {
  position: absolute;
  inset: 48px 0 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: var(--space-8);
  text-align: center;
}

.table-state[hidden] {
  display: none;
}

.table-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-3);
  color: var(--text-tertiary);
}

.table-state h3 {
  font-size: var(--text-base);
  font-weight: 600;
}

.table-state p {
  max-width: 34ch;
  margin-top: var(--space-1);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.table-state .ghost-button {
  margin-top: var(--space-4);
}

dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-dialog);
  background: var(--surface-overlay);
  color: var(--text-primary);
  box-shadow: var(--shadow-overlay);
}

dialog::backdrop {
  background: rgb(10 25 22 / 48%);
  backdrop-filter: blur(3px);
}

.dialog-card {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-6);
}

.dialog-header,
.dialog-actions,
.dialog-actions > div {
  display: flex;
  align-items: center;
}

.dialog-header,
.dialog-actions {
  justify-content: space-between;
  gap: var(--space-4);
}

.dialog-actions {
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
}

.dialog-actions > div {
  gap: var(--space-2);
}

.dialog-date {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--accent);
  background: var(--surface-accent-soft);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.dialog-date strong {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  right: max(var(--space-4), env(safe-area-inset-right));
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
  display: flex;
  min-height: 48px;
  max-width: min(420px, calc(100vw - 32px));
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  background: var(--surface-overlay);
  box-shadow: var(--shadow-overlay);
  color: var(--text-primary);
}

.toast[hidden] {
  display: none;
}

.toast button {
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: var(--space-6);
  background: var(--surface-canvas);
}

.auth-shell {
  width: min(420px, 100%);
}

.auth-card {
  position: relative;
  padding: var(--space-8);
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-dialog);
  background: var(--surface-raised);
  box-shadow: var(--shadow-overlay);
}

.auth-card::after {
  position: absolute;
  top: 30px;
  right: -8px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-round);
  background: var(--surface-canvas);
  content: "";
}

.auth-mark {
  margin-bottom: var(--space-6);
}

.auth-card h1 {
  margin-top: var(--space-1);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.04em;
}

.auth-copy {
  max-width: 34ch;
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-base);
}

.auth-form {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-6);
}

.auth-error {
  display: none;
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.auth-error.is-visible {
  display: block;
  color: var(--danger);
}

.auth-foot {
  margin-top: var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  text-align: center;
}

@media (hover: hover) and (pointer: fine) {
  .rail-link:hover,
  .icon-button:hover,
  .row-action:hover {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .primary-button:hover {
    border-color: var(--accent-hover);
    background: var(--accent-hover);
    box-shadow: 0 2px 4px rgb(11 95 85 / 16%), 0 6px 14px rgb(11 95 85 / 12%);
  }

  .ghost-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-sunken);
    color: var(--text-primary);
  }

  tbody tr:not(.skeleton-row):hover {
    z-index: 1;
    box-shadow: 0 5px 12px rgb(35 57 54 / 9%), 0 1px 3px rgb(35 57 54 / 6%);
    transform: translateY(-2px);
  }

  tbody tr:not(.skeleton-row):hover td {
    border-color: var(--border-default);
    background: var(--surface-overlay);
  }

  tbody tr:hover .row-action {
    opacity: 1;
  }
}

.primary-button:active,
.ghost-button:active,
.icon-button:active,
.filter-button:active,
.row-action:active {
  transform: scale(0.98);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .rail {
    align-items: center;
    padding-right: var(--space-2);
    padding-left: var(--space-2);
  }

  .brand > span:last-child,
  .rail-link:not(.is-active)::after,
  .rail-link {
    font-size: 0;
  }

  .rail-link {
    width: 48px;
    justify-content: center;
    padding: 0;
  }

  .rail-link svg {
    width: 20px;
    height: 20px;
  }

  .rail-stamp {
    width: 52px;
    padding: var(--space-2) var(--space-1);
    text-align: center;
  }

  .rail-stamp span,
  .rail-stamp small {
    display: none;
  }

  .rail-stamp strong {
    font-size: 13px;
    letter-spacing: -0.04em;
  }

  .sync-state,
  .rail-actions form {
    display: none;
  }

  .rail-footer {
    justify-content: center;
  }

  .content-grid {
    grid-template-columns: minmax(288px, 336px) minmax(0, 1fr);
  }

  .keyboard-hint {
    display: none;
  }

  .metric-strip {
    grid-template-columns: 1fr 1fr;
  }

  .metric-primary {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .rail {
    display: none;
  }

  .workspace {
    padding-right: var(--space-4);
    padding-left: var(--space-4);
  }

  .topbar {
    min-height: 64px;
  }

  .topbar .kicker {
    display: none;
  }

  .mobile-brand,
  .mobile-theme {
    display: block;
  }

  .mobile-brand {
    margin-right: -4px;
  }

  .topbar > div:nth-child(2) {
    margin-right: auto;
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .capture-column {
    position: static;
  }

  .compact-action {
    display: none;
  }

  .topbar-actions .ghost-button span {
    display: none;
  }
}

@media (max-width: 660px) {
  .workspace {
    padding-right: var(--space-3);
    padding-bottom: var(--space-6);
    padding-left: var(--space-3);
  }

  .topbar {
    gap: var(--space-2);
  }

  .topbar h1 {
    font-size: var(--text-lg);
  }

  .content-grid {
    gap: var(--space-4);
    padding-top: var(--space-3);
  }

  .metric-strip {
    grid-template-columns: 1fr 1fr;
  }

  .metric-primary {
    min-height: 104px;
  }

  .metric-card {
    min-height: 92px;
    padding: var(--space-3);
  }

  .metric-card strong {
    font-size: 24px;
  }

  .metric-primary strong {
    font-size: 30px;
  }

  .sparkline {
    width: 92px;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .search-box {
    max-width: none;
    flex-basis: 100%;
  }

  .filter-group {
    width: 100%;
  }

  .filter-button {
    flex: 1;
  }

  .table-wrap {
    min-height: 320px;
    overflow-x: visible;
  }

  table,
  tbody {
    display: block;
    width: 100%;
  }

  table {
    padding: 0 var(--space-2) var(--space-2);
  }

  thead {
    display: none;
  }

  tbody tr:not(.skeleton-row) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: var(--space-2);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    background: var(--surface-raised);
  }

  tbody tr:not(.skeleton-row) td {
    display: grid;
    height: auto;
    min-height: 50px;
    align-content: center;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
    background: transparent;
    text-align: left;
  }

  tbody tr:not(.skeleton-row) td:nth-child(odd) {
    border-right: 1px solid var(--border-subtle);
  }

  tbody tr:not(.skeleton-row) td::before {
    color: var(--text-tertiary);
    content: attr(data-label);
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  tbody tr:not(.skeleton-row) .cell-name,
  tbody tr:not(.skeleton-row) .cell-notes,
  tbody tr:not(.skeleton-row) .cell-action {
    grid-column: 1 / -1;
    border-right: 0;
  }

  tbody tr:not(.skeleton-row) .cell-action {
    min-height: 44px;
    border-bottom: 0;
  }

  .notes-text {
    max-width: none;
    white-space: normal;
  }

  .row-action {
    justify-self: start;
    opacity: 1;
  }

  .skeleton-row,
  .skeleton-row td {
    display: block;
    width: 100%;
  }

  .skeleton-row td {
    padding: var(--space-2) 0;
  }

  .dialog-card {
    padding: var(--space-4);
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .dialog-actions > div {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .dialog-actions .text-button {
    justify-content: flex-start;
  }
}

@media (max-width: 420px) {
  .paired-fields {
    grid-template-columns: 1fr;
  }

  .metric-primary {
    grid-template-columns: 1fr 84px;
  }

  .sparkline {
    width: 84px;
  }

  .auth-card {
    padding: var(--space-6);
  }
}

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

  .skeleton-row span {
    animation-duration: 1.4s !important;
  }
}
