.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  min-height: var(--touch-min);
  padding: var(--space-12) var(--space-24);
  border-radius: var(--radius-m);
  font-family: var(--font-sans);
  font-weight: var(--fw-medium);
  font-size: var(--fs-base);
  line-height: 1;
  white-space: nowrap;
  transition: all var(--dur-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
  border-radius: inherit;
}

.btn:active::after { opacity: 0.08; }

.btn-primary {
  background: var(--accent);
  color: #FFF;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-secondary:hover { border-color: var(--line-strong); background: var(--bg); }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}
.btn-ghost:hover { color: var(--ink); background: var(--accent-subtle); }

.btn-danger {
  background: var(--critical-subtle);
  color: var(--critical-text);
}
.btn-danger:hover { background: var(--critical); color: #FFF; }

.btn-full { width: 100%; }

.btn-sm {
  min-height: 36px;
  padding: var(--space-6) var(--space-16);
  font-size: var(--fs-sm);
  border-radius: var(--radius-s);
}

.btn-icon {
  width: var(--touch-min);
  height: var(--touch-min);
  padding: 0;
  border-radius: var(--radius-s);
}

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

.input-group { position: relative; margin-bottom: var(--space-20); }

.input-group label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--ink-2);
  margin-bottom: var(--space-6);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input-field {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-12) var(--space-16);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  font-size: var(--fs-base);
  color: var(--ink);
  transition: border-color var(--dur-normal) var(--ease-out);
}

.input-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.input-field::placeholder { color: var(--ink-3); }

.input-pin {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  text-align: center;
  letter-spacing: 0.3em;
  padding: var(--space-16) var(--space-24);
  min-height: 64px;
}

.input-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: center;
  width: 72px;
  padding: var(--space-8);
}

.input-error { border-color: var(--critical); }
.input-error:focus { box-shadow: 0 0 0 3px var(--critical-subtle); }
.error-msg { color: var(--critical-text); font-size: var(--fs-sm); margin-top: var(--space-6); }

.chip {
  display: inline-flex;
  width: 8px;
  height: 24px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.chip-wide {
  width: 24px;
  height: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-10);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.6;
  white-space: nowrap;
}

.pill-ok { background: var(--ok-subtle); color: var(--ok-text); }
.pill-warn { background: var(--warn-subtle); color: var(--warn-text); }
.pill-critical { background: var(--critical-subtle); color: var(--critical-text); }
.pill-info { background: var(--info-subtle); color: var(--info-text); }
.pill-neutral { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); }

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.counter-row {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-10) 0;
  border-bottom: 1px solid var(--line);
  min-height: 60px;
}

.counter-row:last-child { border-bottom: none; }

.counter-row.uncounted {
  opacity: 0.5;
  border-bottom-style: dashed;
}

.counter-row.uncounted .counter-value { color: var(--ink-3); }

.counter-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-10);
}

.counter-name {
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.counter-controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

.counter-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-s);
  color: var(--ink-2);
  font-size: var(--fs-xl);
  font-weight: var(--fw-regular);
  transition: all var(--dur-fast) var(--ease-out);
  user-select: none;
  -webkit-user-select: none;
}

.counter-btn:hover { background: var(--accent-subtle); color: var(--accent); }
.counter-btn:active { transform: scale(0.92); }
.counter-btn svg { width: 22px; height: 22px; }

.counter-value {
  font-family: var(--font-serif);
  font-size: var(--fs-xl);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: center;
  cursor: pointer;
  padding: var(--space-4);
  border-radius: var(--radius-xs);
  transition: background var(--dur-fast) var(--ease-out);
}

.counter-value:hover { background: var(--surface); }

.counter-status {
  width: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.counter-status svg { width: 14px; height: 14px; }
.counter-status .saved { color: var(--ok); }
.counter-status .saving { color: var(--warn); animation: pulse 1.5s infinite; }
.counter-status .pending { color: var(--ink-3); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.micro-bar {
  height: 6px;
  background: var(--line);
  border-radius: var(--radius-full);
  position: relative;
  overflow: hidden;
  width: 100%;
}

.micro-bar-fill {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease-out);
}

.micro-bar-mark {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 10px;
  background: var(--ink-2);
  border-radius: 1px;
}

.progress-ruler {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-8) 0;
}

.progress-ruler-segment {
  display: flex;
  gap: 3px;
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}

.progress-ruler-segment:hover { background: var(--surface); }
.progress-ruler-segment.active { background: var(--accent-subtle); }

.progress-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line);
  transition: background var(--dur-normal) var(--ease-out);
}

.progress-dot.filled { background: var(--accent); }

.terminal {
  background: var(--terminal-bg);
  color: var(--terminal-fg);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: var(--lh-relaxed);
  padding: var(--space-20);
  border-radius: var(--radius-m);
  position: relative;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.terminal-cursor::after {
  content: '▋';
  color: var(--terminal-accent);
  animation: blink 1.2s step-end infinite;
}

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

.terminal-header {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: var(--fs-xs);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.terminal-dots {
  display: flex;
  gap: 5px;
}
.terminal-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: var(--space-16);
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-12);
}

.stat-card {
  padding: var(--space-16);
  border-radius: var(--radius-m);
  border: 1px solid var(--line);
  background: var(--surface);
}

.stat-value {
  font-family: var(--font-serif);
  font-size: var(--fs-2xl);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: var(--space-4);
}

.stat-label {
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.skeleton {
  background: linear-gradient(90deg, var(--line) 25%, var(--surface) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 2.4s ease-in-out infinite;
  border-radius: var(--radius-xs);
  min-height: 16px;
}

.skeleton-text { height: 16px; width: 80%; margin-bottom: var(--space-8); }
.skeleton-title { height: 28px; width: 60%; margin-bottom: var(--space-12); }
.skeleton-row { height: 60px; width: 100%; margin-bottom: var(--space-4); border-radius: var(--radius-s); }
.skeleton-card { height: 80px; width: 100%; border-radius: var(--radius-m); }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.sync-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--sync-bar-height);
  padding: 0 var(--space-16);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--ink-2);
}

.sync-status {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background var(--dur-normal) var(--ease-out);
}

.sync-dot.synced { background: var(--ok); }
.sync-dot.syncing { background: var(--warn); animation: pulse 1.5s infinite; }
.sync-dot.pending { background: var(--critical); }

.sync-user {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 90;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-12);
  border-radius: var(--radius-s);
  color: var(--ink-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  transition: color var(--dur-fast) var(--ease-out);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  justify-content: center;
}

.nav-item:hover { color: var(--ink-2); }
.nav-item.active { color: var(--accent); }
.nav-item svg { width: 22px; height: 22px; }

.toast-container {
  position: fixed;
  top: calc(var(--sync-bar-height) + var(--space-8));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - var(--space-32));
  max-width: 560px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: toastIn var(--dur-slow) var(--ease-spring) both;
}

.toast.removing { animation: toastOut var(--dur-normal) var(--ease-out) both; }
.toast-ok { border-left: 3px solid var(--ok); }
.toast-warn { border-left: 3px solid var(--warn); }
.toast-error { border-left: 3px solid var(--critical); }
.toast-info { border-left: 3px solid var(--info); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px) scale(0.96); } }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 19, 0.5);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn var(--dur-normal) var(--ease-out) both;
}

.modal {
  width: 100%;
  max-width: 600px;
  max-height: 85dvh;
  background: var(--surface);
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  padding: var(--space-24);
  overflow-y: auto;
  animation: slideUp var(--dur-slow) var(--ease-spring) both;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--line-strong);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-20);
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.check-row {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) 0;
  border-bottom: 1px solid var(--line);
}

.check-box {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease-out);
  cursor: pointer;
}

.check-box.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFF;
}

.check-box svg { width: 14px; height: 14px; opacity: 0; transition: opacity var(--dur-fast); }
.check-box.checked svg { opacity: 1; }

.group-header {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-12) 0 var(--space-8);
  margin-top: var(--space-8);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.group-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.empty-state {
  text-align: center;
  padding: var(--space-48) var(--space-24);
  color: var(--ink-2);
}

.empty-state h3 { margin-bottom: var(--space-8); color: var(--ink); }
.empty-state p { font-size: var(--fs-sm); max-width: 280px; margin: 0 auto; }

.sparkline {
  display: inline-block;
  vertical-align: middle;
}

.sparkline polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-8 { gap: var(--space-8); }
.gap-12 { gap: var(--space-12); }
.gap-16 { gap: var(--space-16); }
.mt-8 { margin-top: var(--space-8); }
.mt-16 { margin-top: var(--space-16); }
.mt-24 { margin-top: var(--space-24); }
.mb-8 { margin-bottom: var(--space-8); }
.mb-16 { margin-bottom: var(--space-16); }
.mb-24 { margin-bottom: var(--space-24); }
.p-16 { padding: var(--space-16); }
